Skip to content

Instantly share code, notes, and snippets.

@donsequitur
Last active March 24, 2019 19:03
Show Gist options
  • Save donsequitur/e45d9dd9e13b217d24ba5dad1390bccb to your computer and use it in GitHub Desktop.
Save donsequitur/e45d9dd9e13b217d24ba5dad1390bccb to your computer and use it in GitHub Desktop.
const fs = require('fs');
const readline = require('readline');
const stream = require('stream');
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
function readLines({ input }) {
const output = new stream.PassThrough({ objectMode: true });
const rl = readline.createInterface({ input });
rl.on("line", line => {
output.write(line);
});
rl.on("close", () => {
output.push(null);
});
return output;
}
const input = fs.createReadStream("./hello.txt");
(async () => {
for await (const line of readLines({ input })) {
await delay(2322);
console.log(line);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment