I am attempting to read a stream line by line and for each line do some async processing. The issue I'm having is how to determine when the operations for all lines are complete. I thought I could use the readline "close" event but that seems to be triggered long before the async operations I've started on the "line" event complete.
Here's the event handlers in question:
logReader.on("line", inputLine => {
self._processLogLine(inputLine, () => {
if (self.streamFinished) {
completionCallback(err);
}
});
});
logReader.on("close", () => {
self.streamFinished = true;
});
The completionCallback method should be called when all line processing on the stream is done.
I've thought about adding counters for line operations started/completed and calling the completionCallback when they match but that seems awkward.
logReader?logReaderis the readline interfacelet logReader = readline.createInterface(self.inputStream);