I recently began experimenting with async iterators, using the --harmony
flag in Node 9.5. After reading through the MDN docs, I figured that it might be interesting to make a function that takes the values yielded by an async generator function and serves them as an SSE event stream. The following is a simple, contrived example:
const http = require("http");
const timer = time =>
new Promise(resolve => setTimeout(resolve, time));
async function* counter() {
let counter = 0;