Skip to content

Instantly share code, notes, and snippets.

@rudolph9
Last active July 8, 2018 01:57
Show Gist options
  • Save rudolph9/9cbfdfdf0b4fce044aec08a72dc9d5d2 to your computer and use it in GitHub Desktop.
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
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