@xylabs/threads 3.6.5 → 3.6.7
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/dist/esm/master/implementation.node.js +3 -6
- package/dist/master/implementation.node.js +3 -6
- package/observable.d.ts +1 -0
- package/package.json +8 -8
- package/register.d.ts +1 -0
- package/rollup.config.js +0 -1
- package/src/index.ts +1 -0
- package/src/master/implementation.browser.ts +1 -0
- package/src/master/implementation.node.ts +6 -10
- package/src/master/index.ts +1 -0
- package/src/master/invocation-proxy.ts +2 -0
- package/src/master/pool.ts +1 -0
- package/src/master/spawn.ts +1 -0
- package/src/master/thread.ts +1 -0
- package/src/observable.ts +1 -0
- package/src/serializers.ts +1 -0
- package/src/transferable.ts +1 -0
- package/src/worker/implementation.browser.ts +1 -0
- package/src/worker/implementation.tiny-worker.ts +2 -0
- package/src/worker/implementation.ts +1 -0
- package/src/worker/implementation.worker_threads.ts +1 -0
- package/src/worker/index.ts +1 -0
- package/test/observable-promise.test.ts +2 -0
- package/test/observable.test.ts +1 -0
- package/test/pool.test.ts +15 -10
- package/test/serialization.test.ts +1 -0
- package/test/spawn.chromium.mocha.ts +1 -0
- package/test/spawn.test.ts +1 -0
- package/test/transferables.test.ts +1 -0
- package/test/workers/minmax.ts +1 -0
- package/test/workers/serialization.ts +1 -0
- package/test-tooling/webpack/app-with-inlined-worker.ts +1 -0
- package/test-tooling/webpack/app.ts +1 -0
- package/test-tooling/webpack/webpack.node.config.js +0 -1
- package/test-tooling/webpack/webpack.web.config.js +0 -1
- package/worker.d.ts +1 -0
|
@@ -35,11 +35,10 @@ function detectTsNode() {
|
|
|
35
35
|
return tsNodeAvailable;
|
|
36
36
|
}
|
|
37
37
|
function createTsNodeModule(scriptPath) {
|
|
38
|
-
|
|
38
|
+
return `
|
|
39
39
|
require("ts-node/register/transpile-only");
|
|
40
40
|
require(${JSON.stringify(scriptPath)});
|
|
41
41
|
`;
|
|
42
|
-
return content;
|
|
43
42
|
}
|
|
44
43
|
function rebaseScriptPath(scriptPath, ignoreRegex) {
|
|
45
44
|
const parentCallSite = (0, callsites_3_1_0_1.default)().find((callsite) => {
|
|
@@ -51,17 +50,15 @@ function rebaseScriptPath(scriptPath, ignoreRegex) {
|
|
|
51
50
|
if (callerPath && callerPath.startsWith('file:')) {
|
|
52
51
|
callerPath = (0, node_url_1.fileURLToPath)(callerPath);
|
|
53
52
|
}
|
|
54
|
-
|
|
55
|
-
return rebasedScriptPath;
|
|
53
|
+
return callerPath ? node_path_1.default.join(node_path_1.default.dirname(callerPath), scriptPath) : scriptPath;
|
|
56
54
|
}
|
|
57
55
|
function resolveScriptPath(scriptPath, baseURL) {
|
|
58
56
|
const makeRelative = (filePath) => {
|
|
59
57
|
return node_path_1.default.isAbsolute(filePath) ? filePath : node_path_1.default.join(baseURL || eval('__dirname'), filePath);
|
|
60
58
|
};
|
|
61
|
-
|
|
59
|
+
return typeof __non_webpack_require__ === 'function' ?
|
|
62
60
|
__non_webpack_require__.resolve(makeRelative(scriptPath))
|
|
63
61
|
: eval('require').resolve(makeRelative(rebaseScriptPath(scriptPath, /[/\\]worker_threads[/\\]/)));
|
|
64
|
-
return workerFilePath;
|
|
65
62
|
}
|
|
66
63
|
function initWorkerThreadsWorker() {
|
|
67
64
|
const NativeWorker = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__('worker_threads').Worker : eval('require')('worker_threads').Worker;
|
|
@@ -35,11 +35,10 @@ function detectTsNode() {
|
|
|
35
35
|
return tsNodeAvailable;
|
|
36
36
|
}
|
|
37
37
|
function createTsNodeModule(scriptPath) {
|
|
38
|
-
|
|
38
|
+
return `
|
|
39
39
|
require("ts-node/register/transpile-only");
|
|
40
40
|
require(${JSON.stringify(scriptPath)});
|
|
41
41
|
`;
|
|
42
|
-
return content;
|
|
43
42
|
}
|
|
44
43
|
function rebaseScriptPath(scriptPath, ignoreRegex) {
|
|
45
44
|
const parentCallSite = (0, callsites_3_1_0_1.default)().find((callsite) => {
|
|
@@ -51,17 +50,15 @@ function rebaseScriptPath(scriptPath, ignoreRegex) {
|
|
|
51
50
|
if (callerPath && callerPath.startsWith('file:')) {
|
|
52
51
|
callerPath = (0, node_url_1.fileURLToPath)(callerPath);
|
|
53
52
|
}
|
|
54
|
-
|
|
55
|
-
return rebasedScriptPath;
|
|
53
|
+
return callerPath ? node_path_1.default.join(node_path_1.default.dirname(callerPath), scriptPath) : scriptPath;
|
|
56
54
|
}
|
|
57
55
|
function resolveScriptPath(scriptPath, baseURL) {
|
|
58
56
|
const makeRelative = (filePath) => {
|
|
59
57
|
return node_path_1.default.isAbsolute(filePath) ? filePath : node_path_1.default.join(baseURL || eval('__dirname'), filePath);
|
|
60
58
|
};
|
|
61
|
-
|
|
59
|
+
return typeof __non_webpack_require__ === 'function' ?
|
|
62
60
|
__non_webpack_require__.resolve(makeRelative(scriptPath))
|
|
63
61
|
: eval('require').resolve(makeRelative(rebaseScriptPath(scriptPath, /[/\\]worker_threads[/\\]/)));
|
|
64
|
-
return workerFilePath;
|
|
65
62
|
}
|
|
66
63
|
function initWorkerThreadsWorker() {
|
|
67
64
|
const NativeWorker = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__('worker_threads').Worker : eval('require')('worker_threads').Worker;
|
package/observable.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/threads",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.7",
|
|
4
4
|
"description": "Web workers & worker threads as simple as a function call",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -83,19 +83,19 @@
|
|
|
83
83
|
"worker_threads"
|
|
84
84
|
],
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@babel/types": "^7.
|
|
86
|
+
"@babel/types": "^7.25.2",
|
|
87
87
|
"callsites-3-1-0": "npm:callsites@3.1.0",
|
|
88
|
-
"debug": "^4.3.
|
|
88
|
+
"debug": "^4.3.6",
|
|
89
89
|
"is-observable-2-1-0": "npm:is-observable@2.1.0",
|
|
90
90
|
"observable-fns": "^0.6.1"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
93
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
94
94
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
95
|
-
"@types/chai": "^4.3.
|
|
95
|
+
"@types/chai": "^4.3.17",
|
|
96
96
|
"@types/debug": "^4.1.12",
|
|
97
97
|
"@types/execa": "^2.0.0",
|
|
98
|
-
"@types/node": "^
|
|
98
|
+
"@types/node": "^22.1.0",
|
|
99
99
|
"@types/webpack": "^5.28.5",
|
|
100
100
|
"ava": "^6.1.3",
|
|
101
101
|
"chai": "^5.1.1",
|
|
@@ -105,14 +105,14 @@
|
|
|
105
105
|
"puppet-run": "^0.11.4",
|
|
106
106
|
"puppet-run-plugin-mocha": "^0.1.1",
|
|
107
107
|
"raw-loader": "^4.0.2",
|
|
108
|
-
"rimraf": "^
|
|
109
|
-
"rollup": "^4.19.
|
|
108
|
+
"rimraf": "^4.4.1",
|
|
109
|
+
"rollup": "^4.19.2",
|
|
110
110
|
"threads-plugin": "^1.4.0",
|
|
111
111
|
"tiny-worker": "^2.3.0",
|
|
112
112
|
"ts-loader": "^9.5.1",
|
|
113
113
|
"ts-node": "^10.9.2",
|
|
114
114
|
"typescript": "^5.5.4",
|
|
115
|
-
"undici-types": "^6.19.
|
|
115
|
+
"undici-types": "^6.19.5",
|
|
116
116
|
"wavy": "^1.0.4",
|
|
117
117
|
"webpack": "^5.93.0",
|
|
118
118
|
"worker-plugin": "^5.0.1"
|
package/register.d.ts
CHANGED
package/rollup.config.js
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/* eslint-disable import/no-internal-modules */
|
|
2
|
+
/* eslint-disable unicorn/no-process-exit */
|
|
3
|
+
/* eslint-disable sonarjs/no-identical-functions */
|
|
1
4
|
/* eslint-disable unicorn/prefer-logical-operator-over-ternary */
|
|
2
5
|
/* eslint-disable unicorn/prefer-regexp-test */
|
|
3
6
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
@@ -5,7 +8,6 @@
|
|
|
5
8
|
/* eslint-disable unicorn/prefer-event-target */
|
|
6
9
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
10
|
/* eslint-disable unicorn/text-encoding-identifier-case */
|
|
8
|
-
/* eslint-disable unicorn/no-process-exit */
|
|
9
11
|
/// <reference lib="dom" />
|
|
10
12
|
|
|
11
13
|
import { EventEmitter } from 'node:events'
|
|
@@ -56,11 +58,10 @@ function detectTsNode() {
|
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
function createTsNodeModule(scriptPath: string) {
|
|
59
|
-
|
|
61
|
+
return `
|
|
60
62
|
require("ts-node/register/transpile-only");
|
|
61
63
|
require(${JSON.stringify(scriptPath)});
|
|
62
64
|
`
|
|
63
|
-
return content
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
function rebaseScriptPath(scriptPath: string, ignoreRegex: RegExp) {
|
|
@@ -76,9 +77,7 @@ function rebaseScriptPath(scriptPath: string, ignoreRegex: RegExp) {
|
|
|
76
77
|
if (callerPath && callerPath.startsWith('file:')) {
|
|
77
78
|
callerPath = fileURLToPath(callerPath)
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return rebasedScriptPath
|
|
80
|
+
return callerPath ? path.join(path.dirname(callerPath), scriptPath) : scriptPath
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
function resolveScriptPath(scriptPath: string, baseURL?: string | undefined) {
|
|
@@ -87,12 +86,9 @@ function resolveScriptPath(scriptPath: string, baseURL?: string | undefined) {
|
|
|
87
86
|
return path.isAbsolute(filePath) ? filePath : path.join(baseURL || eval('__dirname'), filePath)
|
|
88
87
|
}
|
|
89
88
|
|
|
90
|
-
|
|
91
|
-
typeof __non_webpack_require__ === 'function' ?
|
|
89
|
+
return typeof __non_webpack_require__ === 'function' ?
|
|
92
90
|
__non_webpack_require__.resolve(makeRelative(scriptPath))
|
|
93
91
|
: eval('require').resolve(makeRelative(rebaseScriptPath(scriptPath, /[/\\]worker_threads[/\\]/)))
|
|
94
|
-
|
|
95
|
-
return workerFilePath
|
|
96
92
|
}
|
|
97
93
|
|
|
98
94
|
function initWorkerThreadsWorker(): ImplementationExport {
|
package/src/master/index.ts
CHANGED
package/src/master/pool.ts
CHANGED
package/src/master/spawn.ts
CHANGED
package/src/master/thread.ts
CHANGED
package/src/observable.ts
CHANGED
package/src/serializers.ts
CHANGED
package/src/transferable.ts
CHANGED
package/src/worker/index.ts
CHANGED
package/test/observable.test.ts
CHANGED
package/test/pool.test.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable import/no-internal-modules */
|
|
1
2
|
/* eslint-disable @typescript-eslint/no-floating-promises */
|
|
2
3
|
/* eslint-disable require-await */
|
|
3
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
@@ -8,6 +9,9 @@ import test from 'ava'
|
|
|
8
9
|
import { Pool, spawn, Worker } from '../src/index'
|
|
9
10
|
import { PoolEventType, QueuedTask } from '../src/master/pool'
|
|
10
11
|
|
|
12
|
+
const workerPath = './workers/hello-world'
|
|
13
|
+
const HELLO_WORLD = 'Hello World'
|
|
14
|
+
|
|
11
15
|
test.serial('thread pool basics work and events are emitted', async (t) => {
|
|
12
16
|
const events: Pool.Event[] = []
|
|
13
17
|
let spawnCalled = 0
|
|
@@ -15,7 +19,7 @@ test.serial('thread pool basics work and events are emitted', async (t) => {
|
|
|
15
19
|
|
|
16
20
|
const spawnHelloWorld = () => {
|
|
17
21
|
spawnCalled++
|
|
18
|
-
return spawn<() => string>(new Worker(
|
|
22
|
+
return spawn<() => string>(new Worker(workerPath))
|
|
19
23
|
}
|
|
20
24
|
const pool = Pool(spawnHelloWorld, 3)
|
|
21
25
|
pool.events().subscribe((event) => events.push(event))
|
|
@@ -32,7 +36,7 @@ test.serial('thread pool basics work and events are emitted', async (t) => {
|
|
|
32
36
|
await pool.queue(async (helloWorld) => {
|
|
33
37
|
taskFnCalled++
|
|
34
38
|
const result = await helloWorld()
|
|
35
|
-
t.is(result,
|
|
39
|
+
t.is(result, HELLO_WORLD)
|
|
36
40
|
return result
|
|
37
41
|
})
|
|
38
42
|
|
|
@@ -55,7 +59,7 @@ test.serial('thread pool basics work and events are emitted', async (t) => {
|
|
|
55
59
|
workerID: 1,
|
|
56
60
|
},
|
|
57
61
|
{
|
|
58
|
-
returnValue:
|
|
62
|
+
returnValue: HELLO_WORLD,
|
|
59
63
|
taskID: 1,
|
|
60
64
|
type: Pool.EventType.taskCompleted,
|
|
61
65
|
workerID: 1,
|
|
@@ -73,7 +77,7 @@ test.serial('thread pool basics work and events are emitted', async (t) => {
|
|
|
73
77
|
test.serial('pool.completed() works', async (t) => {
|
|
74
78
|
const returned: any[] = []
|
|
75
79
|
|
|
76
|
-
const spawnHelloWorld = () => spawn(new Worker(
|
|
80
|
+
const spawnHelloWorld = () => spawn(new Worker(workerPath))
|
|
77
81
|
const pool = Pool(spawnHelloWorld, 2)
|
|
78
82
|
|
|
79
83
|
for (let i = 0; i < 3; i++) {
|
|
@@ -84,11 +88,11 @@ test.serial('pool.completed() works', async (t) => {
|
|
|
84
88
|
|
|
85
89
|
await pool.completed()
|
|
86
90
|
|
|
87
|
-
t.deepEqual(returned, [
|
|
91
|
+
t.deepEqual(returned, [HELLO_WORLD, HELLO_WORLD, HELLO_WORLD])
|
|
88
92
|
})
|
|
89
93
|
|
|
90
94
|
test.serial('pool.completed() proxies errors', async (t) => {
|
|
91
|
-
const spawnHelloWorld = () => spawn(new Worker(
|
|
95
|
+
const spawnHelloWorld = () => spawn(new Worker(workerPath))
|
|
92
96
|
const pool = Pool(spawnHelloWorld, 2)
|
|
93
97
|
|
|
94
98
|
pool.queue(async () => {
|
|
@@ -100,7 +104,7 @@ test.serial('pool.completed() proxies errors', async (t) => {
|
|
|
100
104
|
})
|
|
101
105
|
|
|
102
106
|
test.serial('pool.completed(true) works', async (t) => {
|
|
103
|
-
const spawnHelloWorld = () => spawn(new Worker(
|
|
107
|
+
const spawnHelloWorld = () => spawn(new Worker(workerPath))
|
|
104
108
|
const pool = Pool(spawnHelloWorld, 2)
|
|
105
109
|
|
|
106
110
|
await pool.completed(true)
|
|
@@ -108,9 +112,10 @@ test.serial('pool.completed(true) works', async (t) => {
|
|
|
108
112
|
})
|
|
109
113
|
|
|
110
114
|
test.serial('pool.settled() does not reject on task failure', async (t) => {
|
|
115
|
+
// eslint-disable-next-line sonarjs/no-unused-collection
|
|
111
116
|
const returned: any[] = []
|
|
112
117
|
|
|
113
|
-
const spawnHelloWorld = () => spawn(new Worker(
|
|
118
|
+
const spawnHelloWorld = () => spawn(new Worker(workerPath))
|
|
114
119
|
const pool = Pool(spawnHelloWorld, 2)
|
|
115
120
|
|
|
116
121
|
pool.queue(async (helloWorld) => {
|
|
@@ -129,7 +134,7 @@ test.serial('pool.settled() does not reject on task failure', async (t) => {
|
|
|
129
134
|
})
|
|
130
135
|
|
|
131
136
|
test.serial('pool.settled(true) works', async (t) => {
|
|
132
|
-
const spawnHelloWorld = () => spawn(new Worker(
|
|
137
|
+
const spawnHelloWorld = () => spawn(new Worker(workerPath))
|
|
133
138
|
const pool = Pool(spawnHelloWorld, 2)
|
|
134
139
|
|
|
135
140
|
await pool.settled(true)
|
|
@@ -138,7 +143,7 @@ test.serial('pool.settled(true) works', async (t) => {
|
|
|
138
143
|
|
|
139
144
|
test.serial('task.cancel() works', async (t) => {
|
|
140
145
|
const events: Pool.Event[] = []
|
|
141
|
-
const spawnHelloWorld = () => spawn(new Worker(
|
|
146
|
+
const spawnHelloWorld = () => spawn(new Worker(workerPath))
|
|
142
147
|
const pool = Pool(spawnHelloWorld, 1)
|
|
143
148
|
|
|
144
149
|
pool.events().subscribe((event) => events.push(event))
|
package/test/spawn.test.ts
CHANGED
package/test/workers/minmax.ts
CHANGED
package/worker.d.ts
CHANGED