DEV Community

deexter
deexter

Posted on

1

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)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay