I have a Node v10.14.1 program that reads a CSV file line-by-line using the readline Interface
My .on('line')
is an async
callback performs some operations which read/write from a db, thus I use async/await
to deal with the promises.
A short version of the program's code block of interest would look something like:
const readline = require('readline');
const filesystem = require('fs');
const reader = readline.createInterface({
input: filesystem.createReadStream(pathToSomeCSV)
});
reader.on('line', async (line) => {
await doSomeDBStuff();
})
If I leave the above the way it is, the process does not exit. However, if I
reader.on('close', () => {process.exit()});
then the process exits prior to all of the on('line')
callbacks finishing and their promises resolving.
My question is: is there a way to say "Upon all lines being read AND all on('line')
callbacks being completed with their promises resolved, then exit the process (I assume with process.exit()
)"?