Skip to content

Instantly share code, notes, and snippets.

@rystsov
Created October 13, 2016 15:21
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 rystsov/018ff69ee32f116dc8d209cfc7de7c56 to your computer and use it in GitHub Desktop.
Save rystsov/018ff69ee32f116dc8d209cfc7de7c56 to your computer and use it in GitHub Desktop.
let flag = true;
async function frozen(promise) {
flag = await promise;
console.info("done");
}
let complete = null;
frozen(new Promise((reply, reject) => {
complete = reply;
}));
// you'll never see 'done'
complete(false);
// even after you complete the promise
// because js may keep a promise on the event loop
// even if it was completed on the same 'thread'
while (flag) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment