Last active
March 29, 2019 23:13
-
-
Save cmdcolin/e88307f6255c85ac534b903a09b73825 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
// from https://stackoverflow.com/questions/43638105/how-to-get-synchronous-readline-or-simulate-it-using-async-in-nodejs | |
const readline=require('readline') | |
const rl = readline.createInterface({ input: process.stdin , output: process.stdout }); | |
const getLine = (function () { | |
const getLineGen = (async function* () { | |
for await (const line of rl) { | |
yield line; | |
} | |
})(); | |
return async () => ((await getLineGen.next()).value); | |
})(); | |
const main = async () => { | |
const a = await getLine() | |
const b = await getLine() | |
console.log('first two lines', a, b); | |
const lines = [] | |
while ((line = await getLine())){ | |
lines.push(line) | |
} | |
console.log('rest', lines) | |
process.exit(0); | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment