node-csvtojson
node-csvtojson copied to clipboard
Thennable/Promise Implentation
Hey, opening this per suggestion in #339
The returned fromFile()
Promise is not spec compliant so it does not resolve if you call then
or await
on it at a later point.
For example, this code hangs forever on the await
, but with a standard Promise implementation it would work:
const dataPromise = csv().fromFile('my-data.csv'))
async function doSomeStuff (name) {
const data = await dataPromise // This will hang forever!
return data.find(d => d.name === name)
}
Until a solution is PR'd you can simply do this if you'd like to start parsing but don't want to immediately wait for the result:
const dataPromise = csv().fromFile('my-data.csv')).then((result) => Promise.resolve(result))
async function doSomeStuff (name) {
const data = await dataPromise // Yay, it works now!
return data.find(d => d.name === name)
}