"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createDeferred = exports.deferred = void 0; /** * Creates a new `DeferredPromise` * * ```typescript import {deferred} from '@kwsites/promise-deferred`; ``` */ function deferred() { let done; let fail; let status = 'pending'; const promise = new Promise((_done, _fail) => { done = _done; fail = _fail; }); return { promise, done(result) { if (status === 'pending') { status = 'resolved'; done(result); } }, fail(error) { if (status === 'pending') { status = 'rejected'; fail(error); } }, get fulfilled() { return status !== 'pending'; }, get status() { return status; }, }; } exports.deferred = deferred; /** * Alias of the exported `deferred` function, to help consumers wanting to use `deferred` as the * local variable name rather than the factory import name, without needing to rename on import. * * ```typescript import {createDeferred} from '@kwsites/promise-deferred`; ``` */ exports.createDeferred = deferred; /** * Default export allows use as: * * ```typescript import deferred from '@kwsites/promise-deferred`; ``` */ exports.default = deferred; //# sourceMappingURL=index.js.map