Skip to content

Instantly share code, notes, and snippets.

@getify
Created December 5, 2020 01:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getify/617c3fa3c835eac4c0f8adb739d62ab8 to your computer and use it in GitHub Desktop.
Save getify/617c3fa3c835eac4c0f8adb739d62ab8 to your computer and use it in GitHub Desktop.
the "problem" with asynchronous closing of an async iterator
async function *getStuff(urls) {
showSpinner();
try {
for (let url of urls) {
let resp = await fetch(url);
yield await resp.json();
}
}
finally {
hideSpinner();
}
}
var it = getStuff(contentURLs);
cancelBtn.addEventListener("click",() => it.return(),false);
for await (let stuff of it) {
render(stuff);
}
showSummary();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment