I am trying to figure out a way to open a Node.js Stream to read a text/CSV file as a Stream, so that:
- Read a batch of lines
- Pause the reading
- Do some async processing: Parse all lines to an array of objects, then send them to an API.
- Resume reading
- Go to step 1
I have been using readline with some success, but it doesn't quite work because pause() doesn't stop it right away, and it keeps reading more lines while the previous batch is still processing. The end result is the downstream API call chokes on concurrent batches, and I get throttled.
I would like to "close the faucet" while a batch is processed, so I can backoff if I get throttled, backoff, then retry until the batch is fully processed, THEN I can resume reading.
There is an old package event-stream based on split that handle the line splitting, but both projects are archived.
Is this something that can be solved with a Transform Stream