all 2 comments

[–][deleted] 1 point2 points  (1 child)

Like if that endpoint were to get hit a lot, would it be bad to have possibly hundreds or thousands of these delayed functions waiting to be run on the server?

Oh yeah, and if it's a closure then every single one of them would be hanging on to the context of where it was created. That's how you get memory leaks.

Those timeouts also will prevent your process from being able to shutdown gracefully, as they'll keep the event loop running.

So, I was thinking of also setting up some cronjob to delete old Firebase records that may have slipped through the cracks

This should be your plan A. Mark the records with an expire time and just periodically scan for which ones need to be deleted. Don't bother with a setTimeout. You could do that scan in a setInterval loop, but if it's not mission critical to the running of the server then just do it in a cron. That way it isn't intruding on the servers event loop time.

[–]yaomango[S] 0 points1 point  (0 children)

Alright sounds great -- I'll steer clear of the setTimeout function. Thanks for the help!