Skip to content

Commit

Permalink
v0.4.3, return .waitAsync to next tick instead of Promise.all
Browse files Browse the repository at this point in the history
  • Loading branch information
zheksoon committed Apr 4, 2024
1 parent 4f4cdbf commit 8dac7bc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dioma",
"version": "0.4.1",
"version": "0.4.3",
"description": "Elegant dependency injection container for vanilla JavaScript and TypeScript",
"license": "MIT",
"repository": {
Expand Down
5 changes: 4 additions & 1 deletion src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ export class Container {
};

waitAsync = async () => {
await Promise.all(this.pendingPromiseMap.values());
// // The solution doesn't work correctly in all cases
// // because at the moment of the call not all promises are in the map
// await Promise.all(this.pendingPromiseMap.values());
return new Promise<void>((resolve) => setTimeout(resolve, 0));
};

register<T extends Token<any>>(descriptor: TokenValueDescriptor<T>): void;
Expand Down
9 changes: 2 additions & 7 deletions test/dioma.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { beforeEach, describe, expect, it } from "vitest";
import {
ArgumentsError,
AsyncDependencyCycleError,
// AsyncDependencyCycleError,
Container,
DependencyCycleError,
Expand Down Expand Up @@ -816,14 +817,8 @@ describe("Dioma", () => {

await globalContainer.waitAsync();

expect(errorA).toBe(null);
expect(errorA).toBeInstanceOf(AsyncDependencyCycleError);
expect(errorB).toBe(null);

expect(instance).toBeInstanceOf(CircularDependencyA);
expect(instance.instanceB).toBeInstanceOf(CircularDependencyB);

expect(instance.instanceB.instanceA).not.toBe(instance);
expect(instance.instanceB).not.toBe(instance.instanceB.instanceA.instanceB);
});

it("should be able to inject async for container scope", async () => {
Expand Down

0 comments on commit 8dac7bc

Please sign in to comment.