UNPKG

@naturalcycles/js-lib

Version:

Standard library for universal (browser + Node.js) javascript

18 lines (17 loc) 539 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pState = pState; const UNIQUE_VALUE = Symbol('unique'); /** * Returns the state of the Promise, one of: * - pending * - resolved * - rejected * * Based on: https://makandracards.com/makandra/46681-javascript-how-to-query-the-state-of-a-native-promise */ async function pState(p) { return await Promise.race([p, Promise.resolve(UNIQUE_VALUE)]).then(v => { return v === UNIQUE_VALUE ? 'pending' : 'resolved'; }, () => 'rejected'); }