Created
November 17, 2018 10:01
-
-
Save phenax/bb7a1b0447f44e1024edfd6de89f91d5 to your computer and use it in GitHub Desktop.
Revisions
-
phenax created this gist
Nov 17, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ const promiseState = status => ({ status }); const PROMISE_STATE = { PENDING: promiseState('PENDING'), RESOLVED: promiseState('RESOLVED'), REJECTED: promiseState('REJECTED'), }; const getPromiseStatus = promise => Promise.race([ promise, Promise.resolve(PROMISE_STATE.PENDING) ]) .then(r => r === PROMISE_STATE.PENDING ? PROMISE_STATE.PENDING : PROMISE_STATE.RESOLVED) .catch(e => PROMISE_STATE.REJECTED); await getPromiseStatus(teraPromise); // >> { status: 'PENDING' }