Any ideas of how to fix this 'f' function(paralell), the output nedd to look
f's activity starts.
f's activity starts.
f's activity starts.
f's activity ends.
f's activity ends.
f's activity ends.
Done.
Sometimes works, but not always, any ideas of how to fixed(the task is to not modify the 'f' function).
Thank you.
function f(cb) {
console.log("f's activity starts.");
var t = Math.random() * 500; //gives a num between 0 and 1000
function onActivityDone() {
console.log("f's activity ends.");
if (cb) cb();
}
setTimeout(onActivityDone, t);
}
function final() {
console.log('Done');
}
function first() {
final();
}
f()
{
f()
{
f(first)
};
};
ffunction... Ifvar tis0, thenonActivityDoneis triggered immediately afterffinished execution.Math.random()is random, so you don't have any control on the time of execution ofonActivityDonefunction, and the same withcb. The only knowledge is that it will happen within a second.