@anonaddy/omni-worker 0.1.0 → 0.2.0
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.
- package/README.md +22 -14
- package/dist/cjs/helpers/builder.js +22 -0
- package/dist/cjs/helpers/builder.js.map +1 -0
- package/dist/cjs/helpers/pool.js +9 -0
- package/dist/cjs/helpers/pool.js.map +1 -0
- package/dist/cjs/node/builder/helpers.js +14 -28
- package/dist/cjs/node/builder/helpers.js.map +1 -1
- package/dist/cjs/node/builder/index.js +2 -1
- package/dist/cjs/node/builder/index.js.map +1 -1
- package/dist/cjs/node/index.js +110 -51
- package/dist/cjs/node/index.js.map +1 -1
- package/dist/cjs/node/pool.js +131 -73
- package/dist/cjs/node/pool.js.map +1 -1
- package/dist/cjs/node.js +6 -0
- package/dist/cjs/node.js.map +1 -0
- package/dist/cjs/types/helpers.js +11 -0
- package/dist/cjs/types/helpers.js.map +1 -0
- package/dist/cjs/types/node-omni-worker.js +3 -0
- package/dist/cjs/types/node-omni-worker.js.map +1 -0
- package/dist/cjs/types/web-omni-worker.js +3 -0
- package/dist/cjs/types/web-omni-worker.js.map +1 -0
- package/dist/cjs/web/builder/helpers.js +9 -0
- package/dist/cjs/web/builder/helpers.js.map +1 -0
- package/dist/cjs/{node/builder/node.js → web/builder/index.js} +10 -17
- package/dist/cjs/web/builder/index.js.map +1 -0
- package/dist/cjs/web/builder/model.js +3 -0
- package/dist/cjs/web/builder/model.js.map +1 -0
- package/dist/cjs/web/index.js +156 -0
- package/dist/cjs/web/index.js.map +1 -0
- package/dist/cjs/web/pool.js +143 -0
- package/dist/cjs/web/pool.js.map +1 -0
- package/dist/cjs/web/provider/helpers.js +9 -0
- package/dist/cjs/web/provider/helpers.js.map +1 -0
- package/dist/cjs/web/provider/index.js +69 -0
- package/dist/cjs/web/provider/index.js.map +1 -0
- package/dist/cjs/web/provider/model.js +3 -0
- package/dist/cjs/web/provider/model.js.map +1 -0
- package/dist/cjs/web.js +8 -0
- package/dist/cjs/web.js.map +1 -0
- package/dist/mjs/helpers/builder.js +16 -0
- package/dist/mjs/helpers/builder.js.map +1 -0
- package/dist/mjs/helpers/pool.js +6 -0
- package/dist/mjs/helpers/pool.js.map +1 -0
- package/dist/mjs/node/builder/helpers.js +14 -27
- package/dist/mjs/node/builder/helpers.js.map +1 -1
- package/dist/mjs/node/builder/index.js +4 -3
- package/dist/mjs/node/builder/index.js.map +1 -1
- package/dist/mjs/node/index.js +111 -51
- package/dist/mjs/node/index.js.map +1 -1
- package/dist/mjs/node/pool.js +132 -73
- package/dist/mjs/node/pool.js.map +1 -1
- package/dist/mjs/node.js +2 -0
- package/dist/mjs/node.js.map +1 -0
- package/dist/mjs/types/helpers.js +8 -0
- package/dist/mjs/types/helpers.js.map +1 -0
- package/dist/mjs/types/node-omni-worker.js +2 -0
- package/dist/mjs/types/node-omni-worker.js.map +1 -0
- package/dist/mjs/types/web-omni-worker.js +2 -0
- package/dist/mjs/types/web-omni-worker.js.map +1 -0
- package/dist/mjs/web/builder/helpers.js +6 -0
- package/dist/mjs/web/builder/helpers.js.map +1 -0
- package/dist/mjs/web/builder/index.js +10 -0
- package/dist/mjs/web/builder/index.js.map +1 -0
- package/dist/mjs/web/builder/model.js +2 -0
- package/dist/mjs/web/builder/model.js.map +1 -0
- package/dist/mjs/web/index.js +120 -0
- package/dist/mjs/web/index.js.map +1 -0
- package/dist/mjs/web/pool.js +140 -0
- package/dist/mjs/web/pool.js.map +1 -0
- package/dist/mjs/web/provider/helpers.js +6 -0
- package/dist/mjs/web/provider/helpers.js.map +1 -0
- package/dist/mjs/web/provider/index.js +32 -0
- package/dist/mjs/web/provider/index.js.map +1 -0
- package/dist/mjs/web/provider/model.js +2 -0
- package/dist/mjs/web/provider/model.js.map +1 -0
- package/dist/mjs/web.js +3 -0
- package/dist/mjs/web.js.map +1 -0
- package/dist/types/helpers/builder.d.ts +2 -0
- package/dist/types/helpers/builder.d.ts.map +1 -0
- package/dist/types/helpers/pool.d.ts +2 -0
- package/dist/types/helpers/pool.d.ts.map +1 -0
- package/dist/types/node/builder/helpers.d.ts +0 -1
- package/dist/types/node/builder/helpers.d.ts.map +1 -1
- package/dist/types/node/builder/index.d.ts +2 -2
- package/dist/types/node/builder/index.d.ts.map +1 -1
- package/dist/types/node/index.d.ts +15 -13
- package/dist/types/node/index.d.ts.map +1 -1
- package/dist/types/node/pool.d.ts +4 -3
- package/dist/types/node/pool.d.ts.map +1 -1
- package/dist/types/node.d.ts +3 -0
- package/dist/types/node.d.ts.map +1 -0
- package/dist/types/types/helpers.d.ts +6 -0
- package/dist/types/types/helpers.d.ts.map +1 -0
- package/dist/types/types/node-omni-worker.d.ts +90 -0
- package/dist/types/types/node-omni-worker.d.ts.map +1 -0
- package/dist/types/types/web-omni-worker.d.ts +103 -0
- package/dist/types/types/web-omni-worker.d.ts.map +1 -0
- package/dist/types/web/builder/helpers.d.ts +3 -0
- package/dist/types/web/builder/helpers.d.ts.map +1 -0
- package/dist/types/web/builder/index.d.ts +8 -0
- package/dist/types/web/builder/index.d.ts.map +1 -0
- package/dist/types/web/builder/model.d.ts +11 -0
- package/dist/types/web/builder/model.d.ts.map +1 -0
- package/dist/types/web/index.d.ts +35 -0
- package/dist/types/web/index.d.ts.map +1 -0
- package/dist/types/web/pool.d.ts +31 -0
- package/dist/types/web/pool.d.ts.map +1 -0
- package/dist/types/web/provider/helpers.d.ts +2 -0
- package/dist/types/web/provider/helpers.d.ts.map +1 -0
- package/dist/types/web/provider/index.d.ts +16 -0
- package/dist/types/web/provider/index.d.ts.map +1 -0
- package/dist/types/web/provider/model.d.ts +7 -0
- package/dist/types/web/provider/model.d.ts.map +1 -0
- package/dist/types/web.d.ts +4 -0
- package/dist/types/web.d.ts.map +1 -0
- package/package.json +23 -9
- package/dist/cjs/index.js +0 -8
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/node/builder/node.js.map +0 -1
- package/dist/mjs/index.js +0 -3
- package/dist/mjs/index.js.map +0 -1
- package/dist/mjs/node/builder/node.js +0 -14
- package/dist/mjs/node/builder/node.js.map +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/node/builder/node.d.ts +0 -7
- package/dist/types/node/builder/node.d.ts.map +0 -1
package/dist/cjs/node/pool.js
CHANGED
@@ -1,86 +1,144 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
7
|
+
var _, done = false;
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
9
|
+
var context = {};
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
14
|
+
if (kind === "accessor") {
|
15
|
+
if (result === void 0) continue;
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
20
|
+
}
|
21
|
+
else if (_ = accept(result)) {
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
23
|
+
else descriptor[key] = _;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
27
|
+
done = true;
|
28
|
+
};
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
30
|
+
var useValue = arguments.length > 2;
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
33
|
+
}
|
34
|
+
return useValue ? value : void 0;
|
35
|
+
};
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
39
|
+
};
|
2
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
41
|
exports.NodeOmniWorkerPool = void 0;
|
4
42
|
const _1 = require(".");
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
if (
|
20
|
-
|
21
|
-
this._lastUseIdx = 0;
|
22
|
-
return this._pool[0].use();
|
23
|
-
// any other run
|
43
|
+
const helpers_1 = require("../types/helpers");
|
44
|
+
let NodeOmniWorkerPool = (() => {
|
45
|
+
let _classDecorators = [(0, helpers_1.staticImplements)()];
|
46
|
+
let _classDescriptor;
|
47
|
+
let _classExtraInitializers = [];
|
48
|
+
let _classThis;
|
49
|
+
var NodeOmniWorkerPool = _classThis = class {
|
50
|
+
constructor(from, options) {
|
51
|
+
this._pool = [];
|
52
|
+
this._count = 0;
|
53
|
+
this._lastUseIdx = -1;
|
54
|
+
this.isInitialized = () => this._count > 0;
|
55
|
+
this.getNumOfWorkers = () => this._count;
|
56
|
+
this.use = () => {
|
57
|
+
if (!this.isInitialized()) {
|
58
|
+
return this._from.use();
|
24
59
|
}
|
25
60
|
else {
|
26
|
-
|
27
|
-
|
61
|
+
const lastIdx = this._lastUseIdx;
|
62
|
+
// first run or maxed out
|
63
|
+
if (lastIdx === this._count - 1 ||
|
64
|
+
lastIdx === -1) {
|
65
|
+
this._lastUseIdx = 0;
|
66
|
+
return this._pool[0].use();
|
67
|
+
// any other run
|
68
|
+
}
|
69
|
+
else {
|
70
|
+
this._lastUseIdx = lastIdx + 1;
|
71
|
+
return this._pool[lastIdx + 1].use();
|
72
|
+
}
|
28
73
|
}
|
29
|
-
}
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
this.applyOptions();
|
44
|
-
}
|
45
|
-
/**
|
46
|
-
* First builds the OmniWorkers and then launches a new NodeOmniWorker pool
|
47
|
-
* @param from The (relative) file path from your project's root to the worker .ts file
|
48
|
-
* @param options (Optional) Options object for launching the pool
|
49
|
-
*/
|
50
|
-
static async buildAndLaunch(from, options) {
|
51
|
-
const worker = await _1.NodeOmniWorker.build(from);
|
52
|
-
const pool = NodeOmniWorkerPool.launch(worker, options);
|
53
|
-
return pool;
|
54
|
-
}
|
55
|
-
/**
|
56
|
-
* Launches a new NodeOmniWorker pool according to the options provided
|
57
|
-
* @param worker An already built NodeOmniWorker
|
58
|
-
* @returns A newly created pool
|
59
|
-
*/
|
60
|
-
static launch(worker, options) {
|
61
|
-
const pool = new NodeOmniWorkerPool(worker, options);
|
62
|
-
return pool;
|
63
|
-
}
|
64
|
-
/**
|
65
|
-
* Applies the options provided
|
66
|
-
*/
|
67
|
-
applyOptions() {
|
68
|
-
const { numOfWorkers } = this._options;
|
69
|
-
let count = 0;
|
70
|
-
if (numOfWorkers === undefined) {
|
71
|
-
count = 1;
|
74
|
+
};
|
75
|
+
this.destroy = async () => {
|
76
|
+
const fns = [];
|
77
|
+
this._pool.forEach(w => {
|
78
|
+
const fn = async () => {
|
79
|
+
await w.destroy();
|
80
|
+
};
|
81
|
+
fns.push(fn);
|
82
|
+
});
|
83
|
+
await Promise.all(fns.map(fn => fn()));
|
84
|
+
};
|
85
|
+
this._from = from;
|
86
|
+
this._options = options;
|
87
|
+
this.applyOptions();
|
72
88
|
}
|
73
|
-
|
74
|
-
|
89
|
+
/**
|
90
|
+
* First builds the OmniWorkers and then launches a new NodeOmniWorker pool
|
91
|
+
* @param from The (relative) file path from your project's root to the worker .ts file
|
92
|
+
* @param options (Optional) Options object for launching the pool
|
93
|
+
*/
|
94
|
+
static async buildAndLaunch(from, options = {
|
95
|
+
numOfWorkers: 1
|
96
|
+
}) {
|
97
|
+
const worker = await _1.NodeOmniWorker.build(from);
|
98
|
+
const pool = NodeOmniWorkerPool.launch(worker, options);
|
99
|
+
return pool;
|
75
100
|
}
|
76
|
-
|
77
|
-
|
101
|
+
/**
|
102
|
+
* Launches a new NodeOmniWorker pool according to the options provided
|
103
|
+
* @param worker An already built NodeOmniWorker
|
104
|
+
* @returns A newly created pool
|
105
|
+
*/
|
106
|
+
static launch(worker, options = {
|
107
|
+
numOfWorkers: 1
|
108
|
+
}) {
|
109
|
+
const pool = new NodeOmniWorkerPool(worker, options);
|
110
|
+
return pool;
|
78
111
|
}
|
79
|
-
|
80
|
-
|
81
|
-
|
112
|
+
/**
|
113
|
+
* Applies the options provided
|
114
|
+
*/
|
115
|
+
applyOptions() {
|
116
|
+
const { numOfWorkers } = this._options;
|
117
|
+
let count = 0;
|
118
|
+
if (numOfWorkers === undefined) {
|
119
|
+
count = 1;
|
120
|
+
}
|
121
|
+
else {
|
122
|
+
count = numOfWorkers;
|
123
|
+
}
|
124
|
+
if (count < 1) {
|
125
|
+
throw Error(`number of workers must be at least 1`);
|
126
|
+
}
|
127
|
+
this._count = count;
|
128
|
+
for (let i = 0; i <= count; i++) {
|
129
|
+
this._pool = this._from.clone(count);
|
130
|
+
}
|
82
131
|
}
|
83
|
-
}
|
84
|
-
|
132
|
+
};
|
133
|
+
__setFunctionName(_classThis, "NodeOmniWorkerPool");
|
134
|
+
(() => {
|
135
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
136
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
137
|
+
NodeOmniWorkerPool = _classThis = _classDescriptor.value;
|
138
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
139
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
140
|
+
})();
|
141
|
+
return NodeOmniWorkerPool = _classThis;
|
142
|
+
})();
|
85
143
|
exports.NodeOmniWorkerPool = NodeOmniWorkerPool;
|
86
144
|
//# sourceMappingURL=pool.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/node/pool.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/node/pool.ts"],"names":[],"mappings":"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"}
|
package/dist/cjs/node.js
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.NodeOmniWorker = void 0;
|
4
|
+
var index_1 = require("./node/index");
|
5
|
+
Object.defineProperty(exports, "NodeOmniWorker", { enumerable: true, get: function () { return index_1.NodeOmniWorker; } });
|
6
|
+
//# sourceMappingURL=node.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":";;;AAMA,sCAEsB;AADpB,uGAAA,cAAc,OAAA"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.staticImplements = staticImplements;
|
4
|
+
/**
|
5
|
+
* Applies an interface with static function definitions
|
6
|
+
* @returns The constructor of class T
|
7
|
+
*/
|
8
|
+
function staticImplements() {
|
9
|
+
return (constructor) => { constructor; };
|
10
|
+
}
|
11
|
+
//# sourceMappingURL=helpers.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/types/helpers.ts"],"names":[],"mappings":";;AAIA,4CAEC;AAND;;;GAGG;AACH,SAAgB,gBAAgB;IAC5B,OAAO,CAAc,WAAc,EAAE,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"node-omni-worker.js","sourceRoot":"","sources":["../../../src/types/node-omni-worker.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"web-omni-worker.js","sourceRoot":"","sources":["../../../src/types/web-omni-worker.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.convertToJsUrl = convertToJsUrl;
|
4
|
+
function convertToJsUrl(tsUrl, extension) {
|
5
|
+
tsUrl.pathname = tsUrl.pathname.replace(/\.ts$/, extension);
|
6
|
+
tsUrl.href = tsUrl.href.replace(/\.ts$/, extension);
|
7
|
+
return tsUrl;
|
8
|
+
}
|
9
|
+
//# sourceMappingURL=helpers.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../src/web/builder/helpers.ts"],"names":[],"mappings":";;AAEA,wCAIC;AAJD,SAAgB,cAAc,CAAC,KAAU,EAAE,SAAsB;IAC/D,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC5D,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACpD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
@@ -32,23 +32,16 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
32
32
|
return result;
|
33
33
|
};
|
34
34
|
})();
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
37
|
-
};
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
-
exports.
|
40
|
-
const Comlink = __importStar(require("comlink"));
|
41
|
-
const worker_threads_1 = require("worker_threads");
|
42
|
-
const node_adapter_js_1 = __importDefault(require("comlink/dist/umd/node-adapter.js"));
|
36
|
+
exports.buildWebApiAndWorker = void 0;
|
37
|
+
const Comlink = __importStar(require("comlink/dist/esm/comlink"));
|
43
38
|
const helpers_1 = require("./helpers");
|
44
|
-
const
|
45
|
-
const
|
46
|
-
const
|
47
|
-
const
|
48
|
-
const
|
49
|
-
|
50
|
-
const api = Comlink.wrap((0, node_adapter_js_1.default)(worker));
|
51
|
-
return { api, worker };
|
39
|
+
const buildWebApiAndWorker = (tsUrl, options) => {
|
40
|
+
const extension = options.extension || '.js';
|
41
|
+
const jsUrl = (0, helpers_1.convertToJsUrl)(tsUrl, extension);
|
42
|
+
const worker = new Worker(jsUrl, { type: 'module' });
|
43
|
+
const api = Comlink.wrap(worker);
|
44
|
+
return { jsUrl, worker, api };
|
52
45
|
};
|
53
|
-
exports.
|
54
|
-
//# sourceMappingURL=
|
46
|
+
exports.buildWebApiAndWorker = buildWebApiAndWorker;
|
47
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/builder/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kEAAoD;AACpD,uCAA2C;AAGpC,MAAM,oBAAoB,GAAG,CAClC,KAAU,EACV,OAAqC,EACyB,EAAE;IAEhE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAC;IAC7C,MAAM,KAAK,GAAG,IAAA,wBAAc,EAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAE/C,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAI,MAAM,CAAC,CAAC;IAEpC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AAChC,CAAC,CAAA;AAZY,QAAA,oBAAoB,wBAYhC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../../src/web/builder/model.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,156 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
19
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
20
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
21
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
22
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
23
|
+
var _, done = false;
|
24
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
25
|
+
var context = {};
|
26
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
27
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
28
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
29
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
30
|
+
if (kind === "accessor") {
|
31
|
+
if (result === void 0) continue;
|
32
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
33
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
34
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
35
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
36
|
+
}
|
37
|
+
else if (_ = accept(result)) {
|
38
|
+
if (kind === "field") initializers.unshift(_);
|
39
|
+
else descriptor[key] = _;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
43
|
+
done = true;
|
44
|
+
};
|
45
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
46
|
+
var useValue = arguments.length > 2;
|
47
|
+
for (var i = 0; i < initializers.length; i++) {
|
48
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
49
|
+
}
|
50
|
+
return useValue ? value : void 0;
|
51
|
+
};
|
52
|
+
var __importStar = (this && this.__importStar) || (function () {
|
53
|
+
var ownKeys = function(o) {
|
54
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
55
|
+
var ar = [];
|
56
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
57
|
+
return ar;
|
58
|
+
};
|
59
|
+
return ownKeys(o);
|
60
|
+
};
|
61
|
+
return function (mod) {
|
62
|
+
if (mod && mod.__esModule) return mod;
|
63
|
+
var result = {};
|
64
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
65
|
+
__setModuleDefault(result, mod);
|
66
|
+
return result;
|
67
|
+
};
|
68
|
+
})();
|
69
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
70
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
71
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
72
|
+
};
|
73
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
74
|
+
exports.WebOmniWorker = void 0;
|
75
|
+
const Comlink = __importStar(require("comlink/dist/esm/comlink"));
|
76
|
+
const helpers_1 = require("../types/helpers");
|
77
|
+
const builder_1 = require("./builder");
|
78
|
+
/**
|
79
|
+
* OmniWorker for the web
|
80
|
+
*/
|
81
|
+
let WebOmniWorker = (() => {
|
82
|
+
let _classDecorators = [(0, helpers_1.staticImplements)(), (0, helpers_1.staticImplements)()];
|
83
|
+
let _classDescriptor;
|
84
|
+
let _classExtraInitializers = [];
|
85
|
+
let _classThis;
|
86
|
+
var WebOmniWorker = _classThis = class {
|
87
|
+
constructor(url, options, worker, api) {
|
88
|
+
this.isInitialized = () => this._api !== undefined;
|
89
|
+
this.use = () => {
|
90
|
+
const isInitialized = this.isInitialized();
|
91
|
+
if (isInitialized) {
|
92
|
+
return this._api;
|
93
|
+
}
|
94
|
+
else {
|
95
|
+
throw Error(`worker is not yet initialized. make sure to call the build() function, first`);
|
96
|
+
}
|
97
|
+
};
|
98
|
+
this.destroy = async () => {
|
99
|
+
var _a;
|
100
|
+
(_a = this._worker) === null || _a === void 0 ? void 0 : _a.terminate();
|
101
|
+
};
|
102
|
+
this.clone = (numOfTimes) => {
|
103
|
+
const workers = [];
|
104
|
+
const url = this._url;
|
105
|
+
const options = this._options;
|
106
|
+
for (let i = 0; i <= numOfTimes; i++) {
|
107
|
+
const { worker, api } = (0, builder_1.buildWebApiAndWorker)(url, options);
|
108
|
+
workers.push(new WebOmniWorker(url, options, worker, api));
|
109
|
+
}
|
110
|
+
return workers;
|
111
|
+
};
|
112
|
+
this._url = url;
|
113
|
+
this._options = options;
|
114
|
+
this._worker = worker;
|
115
|
+
this._api = api;
|
116
|
+
return this;
|
117
|
+
}
|
118
|
+
/**
|
119
|
+
* Handles the building of the necessary resources for an OmniWorker to function.
|
120
|
+
* This usually means, building from the consumer's code, creating the comlink
|
121
|
+
* interface between the worker and the main thread as well as the worker itself.
|
122
|
+
*
|
123
|
+
* @param tsUrl A URL object linking to the worker .ts file
|
124
|
+
* @param options Builder options
|
125
|
+
* @returns A WebOmniWorker
|
126
|
+
*/
|
127
|
+
static async build(tsUrl, options = {
|
128
|
+
extension: '.js'
|
129
|
+
}) {
|
130
|
+
const { jsUrl, worker, api } = (0, builder_1.buildWebApiAndWorker)(tsUrl, options);
|
131
|
+
return new WebOmniWorker(jsUrl, options, worker, api);
|
132
|
+
}
|
133
|
+
};
|
134
|
+
__setFunctionName(_classThis, "WebOmniWorker");
|
135
|
+
(() => {
|
136
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
137
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
138
|
+
WebOmniWorker = _classThis = _classDescriptor.value;
|
139
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
140
|
+
})();
|
141
|
+
/**
|
142
|
+
* Expose the functions inside the worker to the rest of the application.
|
143
|
+
* After having exposed the functions, the build step can be initiated.
|
144
|
+
* @param exposable A class, object with functions or a single function to be
|
145
|
+
* exposed to the main thread.
|
146
|
+
*/
|
147
|
+
_classThis.expose = (exposable) => {
|
148
|
+
Comlink.expose(exposable);
|
149
|
+
};
|
150
|
+
(() => {
|
151
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
152
|
+
})();
|
153
|
+
return WebOmniWorker = _classThis;
|
154
|
+
})();
|
155
|
+
exports.WebOmniWorker = WebOmniWorker;
|
156
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kEAAoD;AACpD,8CAAoD;AACpD,uCAAiD;AAGjD;;GAEG;IAGU,aAAa;4BAFzB,IAAA,0BAAgB,GAAc,EAC9B,IAAA,0BAAgB,GAAc;;;;;QAO7B,YACE,GAAQ,EACR,OAAqC,EACrC,MAAc,EACd,GAA4B;YAsC9B,kBAAa,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;YAE9C,QAAG,GAAG,GAAG,EAAE;gBACT,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;gBAC3C,IAAI,aAAa,EAAE,CAAC;oBAClB,OAAO,IAAI,CAAC,IAAK,CAAC;gBACpB,CAAC;qBAAM,CAAC;oBACN,MAAM,KAAK,CAAC,8EAA8E,CAAC,CAAC;gBAC9F,CAAC;YACH,CAAC,CAAA;YAED,YAAO,GAAG,KAAK,IAAI,EAAE;;gBACnB,MAAA,IAAI,CAAC,OAAO,0CAAE,SAAS,EAAE,CAAC;YAC5B,CAAC,CAAC;YAEF,UAAK,GAAG,CAAC,UAAkB,EAAE,EAAE;gBAC7B,MAAM,OAAO,GAAuB,EAAE,CAAC;gBACvC,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;gBACtB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC;gBAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;oBACrC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,8BAAoB,EAAI,GAAG,EAAE,OAAO,CAAC,CAAC;oBAC9D,OAAO,CAAC,IAAI,CAAC,IAAI,aAAa,CAAI,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;gBAChE,CAAC;gBACD,OAAO,OAAO,CAAC;YACjB,CAAC,CAAC;YA5DA,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;YAChB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;YACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;YACtB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;YAChB,OAAO,IAAI,CAAC;QACd,CAAC;QAYD;;;;;;;;WAQG;QACI,MAAM,CAAC,KAAK,CAAC,KAAK,CACvB,KAAU,EACV,UAAwC;YACtC,SAAS,EAAE,KAAK;SACjB;YAED,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,8BAAoB,EAAI,KAAK,EAAE,OAAO,CAAC,CAAC;YACvE,OAAO,IAAI,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACxD,CAAC;;;;;QA9CH,6KAyEC;;;;IAtDC;;;;;OAKG;IACW,iBAAM,GAAG,CAAI,SAAY,EAAQ,EAAE;QAC/C,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,AAFmB,CAEnB;;QA3BU,uDAAa;;;;AAAb,sCAAa"}
|
@@ -0,0 +1,143 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
7
|
+
var _, done = false;
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
9
|
+
var context = {};
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
14
|
+
if (kind === "accessor") {
|
15
|
+
if (result === void 0) continue;
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
20
|
+
}
|
21
|
+
else if (_ = accept(result)) {
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
23
|
+
else descriptor[key] = _;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
27
|
+
done = true;
|
28
|
+
};
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
30
|
+
var useValue = arguments.length > 2;
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
33
|
+
}
|
34
|
+
return useValue ? value : void 0;
|
35
|
+
};
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
39
|
+
};
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
41
|
+
exports.WebOmniWorkerPool = void 0;
|
42
|
+
const _1 = require(".");
|
43
|
+
const helpers_1 = require("../types/helpers");
|
44
|
+
let WebOmniWorkerPool = (() => {
|
45
|
+
let _classDecorators = [(0, helpers_1.staticImplements)()];
|
46
|
+
let _classDescriptor;
|
47
|
+
let _classExtraInitializers = [];
|
48
|
+
let _classThis;
|
49
|
+
var WebOmniWorkerPool = _classThis = class {
|
50
|
+
constructor(from, options) {
|
51
|
+
this._pool = [];
|
52
|
+
this._count = 0;
|
53
|
+
this._lastUseIdx = -1;
|
54
|
+
this.isInitialized = () => this._count > 0;
|
55
|
+
this.getNumOfWorkers = () => this._count;
|
56
|
+
this.use = () => {
|
57
|
+
if (!this.isInitialized()) {
|
58
|
+
return this._from.use();
|
59
|
+
}
|
60
|
+
else {
|
61
|
+
const lastIdx = this._lastUseIdx;
|
62
|
+
// first run or maxed out
|
63
|
+
if (lastIdx === this._count - 1 ||
|
64
|
+
lastIdx === -1) {
|
65
|
+
this._lastUseIdx = 0;
|
66
|
+
return this._pool[0].use();
|
67
|
+
// any other run
|
68
|
+
}
|
69
|
+
else {
|
70
|
+
this._lastUseIdx = lastIdx + 1;
|
71
|
+
return this._pool[lastIdx + 1].use();
|
72
|
+
}
|
73
|
+
}
|
74
|
+
};
|
75
|
+
this.destroy = async () => {
|
76
|
+
const fns = [];
|
77
|
+
this._pool.forEach(w => {
|
78
|
+
const fn = async () => {
|
79
|
+
await w.destroy();
|
80
|
+
};
|
81
|
+
fns.push(fn);
|
82
|
+
});
|
83
|
+
await Promise.all(fns.map(fn => fn()));
|
84
|
+
};
|
85
|
+
this._from = from;
|
86
|
+
this._options = options || { numOfWorkers: 1 };
|
87
|
+
this.applyOptions();
|
88
|
+
}
|
89
|
+
/**
|
90
|
+
* First builds the OmniWorkers and then launches a new WebOmniWorker pool
|
91
|
+
* @param url A URL with the relative file path to the worker .ts file
|
92
|
+
* @param options (Optional) Options object for launching the pool
|
93
|
+
*/
|
94
|
+
static async buildAndLaunch(url, options = {
|
95
|
+
extension: '.js',
|
96
|
+
numOfWorkers: (navigator === null || navigator === void 0 ? void 0 : navigator.hardwareConcurrency) || 1
|
97
|
+
}) {
|
98
|
+
const worker = await _1.WebOmniWorker.build(url, options);
|
99
|
+
const pool = WebOmniWorkerPool.launch(worker, options);
|
100
|
+
return pool;
|
101
|
+
}
|
102
|
+
/**
|
103
|
+
* Launches a new WebOmniWorker pool according to the options provided
|
104
|
+
* @param worker An already built WebOmniWorker
|
105
|
+
* @returns A newly created pool
|
106
|
+
*/
|
107
|
+
static launch(worker, options) {
|
108
|
+
const pool = new WebOmniWorkerPool(worker, options);
|
109
|
+
return pool;
|
110
|
+
}
|
111
|
+
/**
|
112
|
+
* Applies the options provided
|
113
|
+
*/
|
114
|
+
applyOptions() {
|
115
|
+
const { numOfWorkers } = this._options;
|
116
|
+
let count = 0;
|
117
|
+
if (numOfWorkers === undefined) {
|
118
|
+
count = 1;
|
119
|
+
}
|
120
|
+
else {
|
121
|
+
count = numOfWorkers;
|
122
|
+
}
|
123
|
+
if (count < 1) {
|
124
|
+
throw Error(`number of workers must be at least 1`);
|
125
|
+
}
|
126
|
+
this._count = count;
|
127
|
+
for (let i = 0; i <= count; i++) {
|
128
|
+
this._pool = this._from.clone(count);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
};
|
132
|
+
__setFunctionName(_classThis, "WebOmniWorkerPool");
|
133
|
+
(() => {
|
134
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
135
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
136
|
+
WebOmniWorkerPool = _classThis = _classDescriptor.value;
|
137
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
138
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
139
|
+
})();
|
140
|
+
return WebOmniWorkerPool = _classThis;
|
141
|
+
})();
|
142
|
+
exports.WebOmniWorkerPool = WebOmniWorkerPool;
|
143
|
+
//# sourceMappingURL=pool.js.map
|