Created
March 20, 2018 04:10
-
-
Save thiagomr/8e225863bc27fd4ceac65b5c93cff836 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
| import fs from 'fs'; | |
| import readline from 'readline'; | |
| async function process() { | |
| return new Promise((resolve, reject) => { | |
| let stream = fs.createReadStream('/tmp/file.txt'); | |
| let rl = readline.createInterface({ | |
| input: stream | |
| }); | |
| rl.on('line', (line) => { | |
| console.log(line); | |
| }).on('close', () => { | |
| resolve('finished'); | |
| }).on('error', err => { | |
| reject(err); | |
| }) | |
| }); | |
| } | |
| (async function () { | |
| try { | |
| const result = await process(); | |
| console.log(result) | |
| } catch (e) { | |
| console.error(e); | |
| } | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment