UNPKG

async-injection

Version:

A robust lightweight dependency injection library for TypeScript.

27 lines 1.11 kB
import { BindableProvider } from './bindable-provider.js'; import { State } from './state.js'; /** * @inheritDoc * This specialization invokes it's configured Factory asynchronously and waits until it can provide the result. */ export class AsyncFactoryBasedProvider extends BindableProvider { constructor(injector, id, maker) { super(injector, id, maker); } /** * @inheritDoc * This specialization invokes it's configured Factory and provides the result (or invokes the error handler if necessary). */ provideAsState() { let retVal = this.singleton; if (!retVal) { // Wrap the async factory's Promise in an errorHandler aware Promise. // Our contract is that an AsyncFactory may not throw and must return a valid Promise (e.g. pending, resolved, rejected, etc). retVal = State.MakeState(this.makePromiseForObj(this.maker(this.injector), obj => obj)); } if (this.singleton === null) this.singleton = retVal; return retVal; } } //# sourceMappingURL=async-factory-provider.js.map