Skip to content

Instantly share code, notes, and snippets.

@danbri
Created April 8, 2023 00:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danbri/7a50745e141b6c4a40e1581b4f5f5e1e to your computer and use it in GitHub Desktop.
Save danbri/7a50745e141b6c4a40e1581b4f5f5e1e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>async generator tests</title>
</head>
<body onload="main()">
<h1>async generator tests</h1>
<div id="output">hello world.</div>
<script>
async function* asyncGenerator() {
let i = 0;
while (i < 1000) {
yield i++;
}
}
const main = () => {
console.log("Everything loaded, let's go.");
const output = document.getElementById("output");
(async () => {
for await (const num of asyncGenerator()) {
output.innerHTML += `count ${num} <br/>`
console.log(num);
}
})();
console.log("Done.");
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment