Gary Gary - 1 year ago 113
Node.js Question

nodejs Async's whilst

Greeting all,

I want to call a function repeatedly, but wanted each call to run only when the previous call is completed. Does the Async's whilst fit what I need? Or do the calls happen in parallel?



Answer Source

Whilst will do what you need, it runs each function in series. Before each run it will do the "test" function to make sure it should run again.

Their example:

var count = 0;

    function () { return count < 5; },
    function (callback) {
        setTimeout(callback, 1000);
    function (err) {
        // 5 seconds have passed