For reference, Aria's suggestion using pure callbacks looks like this:

var timed_api_call  = function () {
    perform_api_call(array_of_objects.shift(), function (err) {
        if (err) { … }
        setTimeout(timed_api_call, 5000);
    });
}

timed_api_call();

-- Rebecca


On April 28, 2014 at 11:35:33 AM, Matt ([email protected]) wrote:

Use the "async" library and async.forEachSeries, and wrap your callback in a 
setTimeout:

async.forEachSeries(array_of_objects, function (object, cb) {
    perform_api_call(object, function(err) {
        if (err) return cb(err);
        setTimeout(cb, 5000);
    });
}, function (err) {
    ...
});


On Mon, Apr 28, 2014 at 11:31 AM, Folivi Fofo <[email protected]> wrote:
Hi all,

I need to iterate through an array of abjects and perform an api call  then 
wait 5 sec before moving to the next item.

Looking for the way do write it but kinda stuck,

any help would be highly appreciated.

Thanks
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

---
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

---
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to