Skip to content

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

@YuriFontella

Description

@YuriFontella
  • Operating System: Linux
  • Node Version: 19
  • NPM Version: 8
  • csv-parser Version: 3.0.0

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions