Created
June 14, 2019 17:33
-
-
Save robinhouston/ee107c3a848e162ba4c2de9ecc556c35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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