D
D
Daniel Newman2015-03-20 01:52:00
JavaScript
Daniel Newman, 2015-03-20 01:52:00

How to wait for setTimeout to complete in Node.JS?

There is such a problem:

var venFirst = 0;

setTimeout(function(){
venFirst = 1;
}, 9999999999)

console.log(venFirst);

Well, in response, we will immediately get 0. How to stop everything that is below the timeout without killing yourself on the code.
Not with EventEmitter, not with Promises, not with async. Colbeck? Question: how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Savostin, 2015-03-20
@savostin

The most correct option is to put "everything below the timeout" inside the callback function.
And read more about Node.js asynchrony - the differences in the application architecture from the same php are simply gigantic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question