Created
July 19, 2018 12:28
-
-
Save jimmy-collazos/824272c67060fab182d8cf597d1a1659 to your computer and use it in GitHub Desktop.
Helper Promise - isPending()
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 characters
/** | |
* Check if Promise is pendding to resolve. Use in Asyn-Await | |
* | |
* Example; | |
* | |
* const { isPending } = require('promise.helper') | |
* it('Check if promise is pending', async function () { | |
* const promise = load(path); | |
* console.assert(await isPending(promise)) | |
* await promise; | |
* console.assert(!(await isPending(promise))) | |
* }) | |
*/ | |
exports.isPending = (p, _t = {}) => Promise.race([p, _t]).then(v => (v === _t)); |
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 characters
/** | |
* Check if Promise is pendding to resolve. Use in Asyn-Await | |
* | |
* Example; | |
* | |
* import { isPending } from 'promise.helper' | |
* it('Check if promise is pending', async function () { | |
* const promise = load(path); | |
* console.assert(await isPending(promise)) | |
* await promise; | |
* console.assert(!(await isPending(promise))) | |
* }) | |
*/ | |
export const isPending = (p, _t = {}) => Promise.race([p, _t]).then(v => (v === _t)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment