Short answer: No they are asynchronous.
Long answer:
As soon as you do anything asynchronous, inside the parralel callbacks, you can expect Trulu
to get called immediatly after. When you call cb
, it announce that the function returned. When all function have returned it will call the last callback.
So for that reason, if you do a setTimeout
without a time and each functions are returning without anything asynchrone, they might behave as synchronous because Javascript only runs one unit at a time. And since they are probably started in order, it will look as if it run synchronously.
Take this as an example:
var looping = true;
setTimeout(function () {looping = false;}, 1000);
while(looping) {
...
}
This code will never leave as setTimeout will never get triggered. In async.parralel
, I'm almost certain that each callbacks are going to get executed after the current unit is finished running. Which means, that you'll always have your console.log("Trulu")
executed before any of the callbacks inside async.parralel
.
Note
If you're looking for to do synchronous things, you shouldn't use a module called async. It's quite obvious that it's going to be asynchronous.
That said, I feel that there is a big misunderstanding with the term async
. Asynchronous isn't a synonym for parralelism or having things simultaneous. Asynchrone, just means "without order in time". It could be simultaneous but it could be also sequential. To run asynchronous code on Javascript, you have to rely on an event loop.
The event loop can only process one event at a time, setTimeout
is just putting the event on the loop. As soon as an event handler leaves, it gets to the next event and so on.
In your case, since you're not calling cb
inside an event handler, they will be called synchronously as they never leave the current event
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…