mafintosh / csv-parser

Streaming csv parser inspired by binary-csv that aims to be faster than everyone else
MIT License
1.41k stars 134 forks source link

async/await in event headers not work as expected #225

Open YuriFontella opened 1 year ago

YuriFontella commented 1 year ago

Expected Behavior

end event headers before executing writable

Actual Behavior

when there is async/await in the headers event, the next pipe is executed before finalizing event headers

How Do We Reproduce?

const readableStreamFile = fs.createReadStream('big.csv')

const writableStreamFile = new Writable({
  objectMode: true,
  async write(chunk, encoding, next) {
    console.log('writable')

    next()
  }
})

readableStreamFile
  .pipe(csv())
  .on('headers', async (headers) => {
    console.log('before headers')
    for await () {}
    // or
    await fecth()

   console.log('after headers')
  })
  .pipe(writableStreamFile)

// the output will be:
// before headers
// writable
// after headers

My dream is to arrive at the writable with all the headers event code finalized.