S
S
Sergo Sergo2015-04-18 15:27:34
Node.js
Sergo Sergo, 2015-04-18 15:27:34

How to make a synchronous loop in meteor?

How to make a synchronous loop in meteor? There are get requests in the loop, but they do not have time to be executed, as the loop is already scrolling. How to stop the loop until the get request is completed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Shemsedinov, 2015-04-18
@MarcusAurelius

For example, instead of get we will use process.nextTick, which is the same with the callback, just replace it.

var util = require('util');
var j = 0;
function loop() {
  if (++j < 100) {
    console.log(j);
    process.nextTick(loop);
  }
}
process.nextTick(loop);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question