I am new to Node.
I have a script that makes a bunch of async calls, writes the results to a database, then is supposed to finish. However, when the logic finishes executing, the script just sits there and does not exit. I have to ^c or explicitly close the mongoose connection. If I do, it exits.
What is the efficient way to determine that all the results are saved and close the connection? Is there not a way to automatically close when all the the connections are finished? Do I need to keep track of them all myself?
Even if I do, it still blows up on a larger number of tasks. So obviously they were not all done.
With synchronous programming it's easy. Open at the start and close at the end. But with async, there are forks all over the place. How can I know that everything has finished? Do you track all the connections in a datastructure? Do you rely on a connection timeout? There must be an efficient way to do it.
Thanks