I want to run several tasks in parallel and use queue.js of mbostock.I run the following code with using Sleep(),so expecting the other lighter tasks to be finished before the heavy tasks while all of the tasks executed at the same time.But following code result in executing tasks sequentially
2 1 test.html:128
1000 2 test.html:134
4 3 test.html:128
3000 4 test.html:134
6 5 test.html:128
while I was expecting something like(execute every tasks at same time but lighter tasks finish earlier):
2 1 test.html:128
4 3 test.html:128
6 5 test.html:128
1000 2 test.html:134
3000 4 test.html:134
What am I doing wrong? code:
function Sleep(ms) {
var d1 = new Date().getTime();
var d2 = new Date().getTime();
while( d2 < (d1 + ms) ) {
d2 = new Date().getTime();
}
return;
}
var tmp_list = [];
var normal = function(src){
tmp_list.push(src);
console.log(src,tmp_list.length);
}
var sleepy = function(src){
Sleep(5000);
tmp_list.push(src);
console.log(src,tmp_list.length)
};
queue().defer(normal,2)
.defer(sleepy,1000)
.defer(normal,4)
.defer(sleepy,3000)
.defer(normal,6)
.awaitAll(function(){});