viral-viewer-2 5.0.0 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,10 +9,11 @@ class WorkerThreadPool {
|
|
|
9
9
|
* @param scriptPath javascript path for worker execute
|
|
10
10
|
*/
|
|
11
11
|
constructor(maxSize, scriptPath) {
|
|
12
|
+
this._workers = [];
|
|
12
13
|
this.maximumNumberOfWorker = maxSize;
|
|
13
14
|
this.scriptPath = scriptPath;
|
|
14
15
|
// only have 1 workerthread from the begining, we will create more when we need it
|
|
15
|
-
this._workers
|
|
16
|
+
this._workers.push(new worker_thread_1.WorkerThread(scriptPath));
|
|
16
17
|
this._free = [...this._workers];
|
|
17
18
|
this._busy = {};
|
|
18
19
|
this._queue = [];
|
|
@@ -35,20 +36,16 @@ class WorkerThreadPool {
|
|
|
35
36
|
_PumpQueue() {
|
|
36
37
|
//only execute when have queue need to be action
|
|
37
38
|
while (this._queue.length > 0) {
|
|
38
|
-
console.log('action queue');
|
|
39
|
-
console.log(this._free.length, this._workers.length);
|
|
40
39
|
//if we dont have any free worker and can create more, create more
|
|
41
40
|
if (this._free.length == 0 &&
|
|
42
41
|
this._workers.length < this.maximumNumberOfWorker) {
|
|
43
|
-
console.log('create new queue');
|
|
44
42
|
const newWorker = new worker_thread_1.WorkerThread(this.scriptPath);
|
|
45
43
|
this._workers.push(newWorker);
|
|
46
44
|
this._free.push(newWorker);
|
|
47
45
|
}
|
|
48
46
|
//if list of worker temporary reach maximum allowed number, skip for a while then execute later
|
|
49
47
|
if (this._workers.length == this.maximumNumberOfWorker) {
|
|
50
|
-
|
|
51
|
-
return;
|
|
48
|
+
continue;
|
|
52
49
|
}
|
|
53
50
|
const w = this._free.pop();
|
|
54
51
|
this._busy[w.id] = w;
|
|
@@ -60,12 +57,7 @@ class WorkerThreadPool {
|
|
|
60
57
|
workResolve(v);
|
|
61
58
|
// terminate worker
|
|
62
59
|
this._workers = this._workers.filter((x) => x.id != w.id);
|
|
63
|
-
|
|
64
|
-
w.dispose();
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
console.log(error);
|
|
68
|
-
}
|
|
60
|
+
w.dispose();
|
|
69
61
|
// call again
|
|
70
62
|
this._PumpQueue();
|
|
71
63
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-pool.js","sourceRoot":"","sources":["../../../../src/components/worker/base/worker-pool.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAE/C,MAAa,gBAAgB;IAQ3B;;;;OAIG;IACH,YAAY,OAAe,EAAE,UAAkB;
|
|
1
|
+
{"version":3,"file":"worker-pool.js","sourceRoot":"","sources":["../../../../src/components/worker/base/worker-pool.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAE/C,MAAa,gBAAgB;IAQ3B;;;;OAIG;IACH,YAAY,OAAe,EAAE,UAAkB;QAVvC,aAAQ,GAAmB,EAAE,CAAC;QAWpC,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,kFAAkF;QAClF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,4BAAY,CAAC,UAAU,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACtE,CAAC;IACD;;;;OAIG;IACI,OAAO,CA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