Callback Javascript Function Parallel
Solution 1:
I guess your last part should look like this:
f( function() {
f( function() {
f(final)
});
});
And the output will be predicted:
f's activity starts. (index):22
f's activity ends. (index):26
f's activity starts. (index):22
f's activity ends. (index):26
f's activity starts. (index):22
f's activity ends. (index):26
Done
The following code you provided is not even compilable:
f() {
f() {
f(final)
};
};
Maybe you wanted something like this:
f ( f ( f(final)));
But it is incorrect too, because code will be executed in the wrong direction. f(final)
will be executed first!
EDIT
If you need to start 3 tasks in parallel use https://github.com/caolan/async#parallel
Solution 2:
The calls to onActivityDone will not necessarily happen in the same order as the calls to f. This is true regardless of the block structure you have used, which I have never seen done before and only seems to confuse the situation.
setTimeout returns immediately - it is not like a "sleep" function that blocks execution until a certain amount of time has passed, it simply stores the callback and the time to wait and then carries on, and Javascript keeps an internal timer to call the callback when the time comes.
Post a Comment for "Callback Javascript Function Parallel"