Run a function / code after a certain time using nodejs

I am looking for a way to run some code in nodejs in N seconds.

Tried setTimeout (), but it seems to completely block it until the time runs out, but this is not what I want, since my server is still sending and receiving events.

Any tips?

+4
source share
1 answer

Actually, it setTimeoutis asynchronous, so it will not block.

setTimeout(function(){
    // this code will only run when time has ellapsed
}, n * 1000);
// this code will not block, and will only run at the time
+6
source

Source: https://habr.com/ru/post/1547508/


All Articles