async-injection
Version:
A robust lightweight dependency injection library for TypeScript.
31 lines • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncFactoryBasedProvider = void 0;
const bindable_provider_js_1 = require("./bindable-provider.js");
const state_js_1 = require("./state.js");
/**
* @inheritDoc
* This specialization invokes it's configured Factory asynchronously and waits until it can provide the result.
*/
class AsyncFactoryBasedProvider extends bindable_provider_js_1.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_js_1.State.MakeState(this.makePromiseForObj(this.maker(this.injector), obj => obj));
}
if (this.singleton === null)
this.singleton = retVal;
return retVal;
}
}
exports.AsyncFactoryBasedProvider = AsyncFactoryBasedProvider;
//# sourceMappingURL=async-factory-provider.js.map