32 lines
2.3 KiB
JavaScript
32 lines
2.3 KiB
JavaScript
|
/* IMPORT */
|
||
|
import { NOOP } from './constants.js';
|
||
|
/* MAIN */
|
||
|
const makeNakedPromise = () => {
|
||
|
let resolve = NOOP;
|
||
|
let reject = NOOP;
|
||
|
let resolved = false;
|
||
|
let rejected = false;
|
||
|
const promise = new Promise((res, rej) => {
|
||
|
resolve = value => {
|
||
|
resolved = true;
|
||
|
return res(value);
|
||
|
};
|
||
|
reject = value => {
|
||
|
rejected = true;
|
||
|
return rej(value);
|
||
|
};
|
||
|
});
|
||
|
const isPending = () => !resolved && !rejected;
|
||
|
const isResolved = () => resolved;
|
||
|
const isRejected = () => rejected;
|
||
|
return { promise, resolve, reject, isPending, isResolved, isRejected };
|
||
|
};
|
||
|
/* UTILITIES */
|
||
|
makeNakedPromise.wrap = async (fn) => {
|
||
|
const result = makeNakedPromise();
|
||
|
await fn(result);
|
||
|
return result.promise;
|
||
|
};
|
||
|
/* EXPORT */
|
||
|
export default makeNakedPromise;
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9wcm9taXNlLW1ha2UtbmFrZWQvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsWUFBWTtBQUVaLE9BQU8sRUFBQyxJQUFJLEVBQUMsTUFBTSxnQkFBZ0IsQ0FBQztBQUdwQyxVQUFVO0FBRVYsTUFBTSxnQkFBZ0IsR0FBRyxHQUFrQixFQUFFO0lBRTNDLElBQUksT0FBTyxHQUFzQixJQUFJLENBQUM7SUFDdEMsSUFBSSxNQUFNLEdBQWtCLElBQUksQ0FBQztJQUVqQyxJQUFJLFFBQVEsR0FBRyxLQUFLLENBQUM7SUFDckIsSUFBSSxRQUFRLEdBQUcsS0FBSyxDQUFDO0lBRXJCLE1BQU0sT0FBTyxHQUFHLElBQUksT0F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