Skip to content

Commit

Permalink
feat(di): Add isAsync method and useAsyncFactory in Provider class
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Aug 20, 2019
1 parent 370f2aa commit f3bb044
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/di/src/class/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export class Provider<T> implements IProvider<T> {
*/
@Enumerable()
public useFactory: Function;

@Enumerable()
public useAsyncFactory: Function;
/**
*
*/
Expand Down Expand Up @@ -144,6 +147,10 @@ export class Provider<T> implements IProvider<T> {
this._store ? this.store.set("scope", scope) : this._scope;
}

isAsync(): boolean {
return !!this.useAsyncFactory;
}

/**
*
*/
Expand Down
9 changes: 9 additions & 0 deletions packages/di/test/class/Provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,13 @@ describe("Provider", () => {
expect(new Provider(T1).toString()).to.eq("Token:T1");
});
});

describe("isAsync()", () => {
it("should return true", () => {
const provider = new Provider(T1);
provider.useAsyncFactory = async () => "test";

expect(provider.isAsync()).to.eq(true);
});
});
});

0 comments on commit f3bb044

Please # to comment.