I've build my first Node application. It receives a list of offers and then I have to receive prices for each item on that offer.
Now the issue is I'm using for to go through the offers object like so
for(var k = 0; k < offers_object.length; k++){
offer = offers_object[k];
logger.info('Time Loaded is '+Math.floor(new Date() / 1000));
....
some stuff...
....
logger.info('Time request is '+Math.floor(new Date() / 1000));
....
send request
....
some more stuff after the requst
}
Now the problem is that whatever needs to be done inside the for loop seems to not be running synchronous. I'm using an API to request item prices which limits me by 8 requests per second.
And what I'm getting from the timers is:
info: Time Loaded is 1448409307
info: Time Loaded is 1448409307
info: Time Loaded is 1448409307
info: Time Loaded is 1448409307
info: Time Loaded is 1448409307
info: Time Loaded is 1448409307
info: Time Loaded is 1448409307
info: Time request is 1448409308
info: Time request is 1448409308
info: Time request is 1448409308
info: Time request is 1448409308
info: Time request is 1448409308
info: Time request is 1448409308
info: Time request is 1448409309
...some stuff...'s are important. Can you fill them in?offers_objectcorrect?logger.info('Time request is '+Math.floor(new Date() / 1000));is in a callback which gets executed later. The for loop is forced to complete. So the callbacks can never run until the loop finishes.