-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (43 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function qfuncs(data, maxTasks, func, callback) {
console.log("paralell process started.");
//data is an array
//func is paralell function
this.data = data;
this.threads = 0;
this.maxQue = maxTasks;
this.processing = false;
this.finished = false;
this.failed = [];
//
var check = function(dec) {
//console.log(" started");
if (dec)
this.threads--;
while (this.processing && !this.finished);
if (this.finished)
return;
this.processing = true;
for (var i = 0; i < this.maxQue - this.threads; i++)
if (data.length > 0) {
this.threads++;
var item = this.data.pop();
console.log("+" + item.value);
try {
func(item, function(dec) {
check(dec);
});
} catch (ex) {
console.log("!" + item.value);
check(true);
}
} else {
this.finished = true;
this.processing = false;
}
this.processing = false;
//if (!processing && finished && data.length == 0)
//callback(moment());
}
check(false);
return this;
}