Last active
March 24, 2019 19:03
-
-
Save donsequitur/e45d9dd9e13b217d24ba5dad1390bccb to your computer and use it in GitHub Desktop.
This file contains 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 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