UNPKG

@hazae41/future

Version:

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

39 lines (36 loc) 881 B
'use strict'; 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; } } exports.Future = Future; //# sourceMappingURL=future.cjs.map