UNPKG

@hazae41/future

Version:

Just like a Promise but you can manually resolve or reject it

37 lines (35 loc) 860 B
class Future { #resolve; #reject; promise; /** * Just a Promise with a resolve and reject function */ constructor(promise) { if (promise == null) { const { promise, resolve, reject } = Promise.withResolvers(); this.promise = promise; this.#resolve = resolve; this.#reject = reject; } else { this.promise = promise; this.#resolve = () => { }; this.#reject = () => { }; } } static resolve(value) { return new Future(Promise.resolve(value)); } static reject(reason) { return new Future(Promise.reject(reason)); } get resolve() { return this.#resolve; } get reject() { return this.#reject; } } export { Future }; //# sourceMappingURL=future.mjs.map