Skip to content

Instantly share code, notes, and snippets.

@lubien
Last active June 22, 2019 00:59
Show Gist options
  • Save lubien/f16a6fe5d13ee08cf0889ae65aa8ead7 to your computer and use it in GitHub Desktop.
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.
1
2
3
4
5
6
7
8
9
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