DEV Community

deexter
deexter

Posted on

setTimeout in nodeJS

We recently started with building new messaging service, that should be made with request reply pattern.

We had no much experience how nodeJS works so we struggled with setting timeout.
Initialy we thought this should work
Alt Text
If you will write code like us you will never get out of while loop, because setTimeout will never be executed.

It is caused because nodeJs has event loop and you have to pass context
Alt Text

Have you ever struggled with same problem?
Share your ideas.

Top comments (0)