Best exit for this case
#42907
-
I was doing data scrapping with a lot of async operation, the screenshot above show you that my scrapper is done with the async operation but if I exit normally, I will miss some data to get inserted, what is best practice for this case? let waitingInsert = data.length;
// a loop which call the waitForGuildInsert function
async function waitForGuildInsert() {
waitingInsert--;
if (waitingInsert === 0) {
console.log(`Total inserted: ${insertedGuilds.length}`);
await guildModel.bulkInsertOrUpdate(insertedGuilds); // Model
}
} Thank you! |
Beta Was this translation helpful? Give feedback.
Answered by
fzn0x
May 3, 2022
Replies: 1 comment 1 reply
-
Solution: use before exit process.on('beforeExit', async () => {
await something()
process.exit(0) // if you don't close yourself this will run forever
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
fzn0x
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solution: use before exit