Добавлена возможность использования HeavyCalc как singleton

This commit is contained in:
Book Pauk
2022-10-23 18:01:20 +07:00
parent 86aa3511bf
commit ab4d54cc85

View File

@@ -86,10 +86,17 @@ class CalcThread {
}
}
//singleton
let instance = null;
class HeavyCalc {
constructor(opts = {}) {
const singleton = opts.singleton || false;
if (singleton && instance)
return instance;
this.threads = opts.threads || 1;
this.singleton = opts.singleton || false;
this.terminated = false;
this.workers = [];
@@ -99,6 +106,10 @@ class HeavyCalc {
this.workers.push(worker);
this.load.push(0);
}
if (singleton) {
instance = this;
}
}
async run(params) {