Skip to content

Instantly share code, notes, and snippets.

@shussekaido
Created January 9, 2017 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shussekaido/afb93fe027d671023be9f5a5886e9d7e to your computer and use it in GitHub Desktop.
Save shussekaido/afb93fe027d671023be9f5a5886e9d7e to your computer and use it in GitHub Desktop.
Use Promise to wait until polled condition is satisfied
function ensureFooIsSet() {
return new Promise(function (resolve, reject) {
(function waitForFoo(){
if (lib.foo) return resolve();
setTimeout(waitForFoo, 30);
})();
});
}
// http://stackoverflow.com/questions/30505960/use-promise-to-wait-until-polled-condition-is-satisfied
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment