Skip to content

Instantly share code, notes, and snippets.

@drgullin
Forked from MayaLekova/interleave.js
Created January 16, 2019 08:43
Show Gist options
  • Save drgullin/dea91c41539a28c6121e0d82a96dad14 to your computer and use it in GitHub Desktop.
Save drgullin/dea91c41539a28c6121e0d82a96dad14 to your computer and use it in GitHub Desktop.
Interleaving of await and promises
async function pr(v) { console.log("pr(" + v + ")"); }
async function f() { for (var i = 0; i < 10; i++) { await pr(i); } return 0; }
function ct(v) { console.log("counter" + v); if (v > 0) Promise.resolve(v - 1).then(ct); }
ct(10); f();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment