Last active
July 8, 2018 01:57
-
-
Save rudolph9/9cbfdfdf0b4fce044aec08a72dc9d5d2 to your computer and use it in GitHub Desktop.
A simple wait function that returns and promise and puts the waiting macro task queue
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
const wait = callback => new Promise((resolve, reject) => { | |
const end = () => { | |
try { | |
if (callback()) { | |
resolve(true); | |
} else { | |
setImmediate(end); | |
} | |
} catch (error) { | |
reject(error); | |
} | |
}; | |
setImmediate(end); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment