Skip to content

Instantly share code, notes, and snippets.

@robinhouston
Created June 14, 2019 17:33
Show Gist options
  • Save robinhouston/ee107c3a848e162ba4c2de9ecc556c35 to your computer and use it in GitHub Desktop.
Save robinhouston/ee107c3a848e162ba4c2de9ecc556c35 to your computer and use it in GitHub Desktop.
const http = require("http");
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const server = http.createServer(async (req, res) => {
res.writeHead(200, { "Content-Type": "text/plain; charset=UTF-8" });
// Send enough padding to fill up the browser’s buffer
res.write("\u200B".repeat(512));
// Write the chunks one at a time
for (var i = 0; i < 10; i++) {
res.write(`[${i}] Hello, world!\n`);
await sleep(1000);
}
res.end();
});
server.listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment