UNPKG

async-constructor

Version:

The helper functions for creating classes that require asynchronous constructors.

23 lines 870 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.appendAsyncConstructor = void 0; const extra_promise_1 = require("extra-promise"); function appendAsyncConstructor(target, asyncConstructor, args) { async function applyAsyncConstructor() { await Promise.resolve(); await Reflect.apply(asyncConstructor, target, args !== null && args !== void 0 ? args : []); delete target.then; return target; } if ((0, extra_promise_1.isPromiseLike)(target)) { setThenMethod(target, Promise.resolve(target).then(applyAsyncConstructor)); } else { setThenMethod(target, applyAsyncConstructor()); } } exports.appendAsyncConstructor = appendAsyncConstructor; function setThenMethod(target, promise) { target.then = promise.then.bind(promise); } //# sourceMappingURL=append.js.map