Last active
June 22, 2019 00:59
-
-
Save lubien/f16a6fe5d13ee08cf0889ae65aa8ead7 to your computer and use it in GitHub Desktop.
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
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
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 |
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
function process () { | |
return new Promise(resolve => { | |
const lineReader = require('readline').createInterface({ | |
input: require('fs').createReadStream('foo.csv') | |
}) | |
const promises = [] | |
lineReader.on('line', line => { | |
promises.push(timeout(1000, line)) | |
}) | |
lineReader.on('close', () => { | |
resolve(Promise.all(promises)) | |
}) | |
}) | |
} | |
function timeout(n, result) { | |
return new Promise(resolve => setTimeout(() => resolve(result), n)) | |
} | |
async function main () { | |
const data = await process() | |
console.log(data) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment