@xylabs/threads 4.6.4 → 4.7.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/dist/browser/master/implementation.browser.mjs +89 -0
- package/dist/browser/master/implementation.browser.mjs.map +1 -0
- package/dist/browser/worker/worker.browser.mjs +291 -0
- package/dist/browser/worker/worker.browser.mjs.map +1 -0
- package/dist/neutral/index.mjs +1022 -0
- package/dist/neutral/index.mjs.map +1 -0
- package/dist/neutral/master/implementation.mjs +264 -0
- package/dist/neutral/master/implementation.mjs.map +1 -0
- package/dist/neutral/master/index.mjs +988 -0
- package/dist/neutral/master/index.mjs.map +1 -0
- package/dist/neutral/master/pool.mjs +579 -0
- package/dist/neutral/master/pool.mjs.map +1 -0
- package/dist/neutral/master/register.mjs +272 -0
- package/dist/neutral/master/register.mjs.map +1 -0
- package/dist/neutral/master/spawn.mjs +412 -0
- package/dist/neutral/master/spawn.mjs.map +1 -0
- package/dist/neutral/master/thread.mjs +29 -0
- package/dist/neutral/master/thread.mjs.map +1 -0
- package/dist/neutral/observable-promise.mjs +132 -0
- package/dist/neutral/observable-promise.mjs.map +1 -0
- package/dist/neutral/observable.mjs +31 -0
- package/dist/neutral/observable.mjs.map +1 -0
- package/dist/node/master/implementation.node.mjs +154 -0
- package/dist/node/master/implementation.node.mjs.map +1 -0
- package/dist/node/worker/worker.node.mjs +304 -0
- package/dist/node/worker/worker.node.mjs.map +1 -0
- package/dist/{common.d.ts → types/common.d.ts} +5 -1
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/{master → types/master}/get-bundle-url.browser.d.ts +1 -0
- package/dist/types/master/get-bundle-url.browser.d.ts.map +1 -0
- package/dist/{master → types/master}/implementation.browser.d.ts +2 -1
- package/dist/types/master/implementation.browser.d.ts.map +1 -0
- package/dist/{master → types/master}/implementation.d.ts +4 -1
- package/dist/types/master/implementation.d.ts.map +1 -0
- package/dist/{master → types/master}/implementation.node.d.ts +2 -1
- package/dist/types/master/implementation.node.d.ts.map +1 -0
- package/dist/types/master/index.d.ts +13 -0
- package/dist/types/master/index.d.ts.map +1 -0
- package/dist/{master → types/master}/invocation-proxy.d.ts +2 -1
- package/dist/types/master/invocation-proxy.d.ts.map +1 -0
- package/dist/{master → types/master}/pool-types.d.ts +16 -1
- package/dist/types/master/pool-types.d.ts.map +1 -0
- package/dist/types/master/pool.d.ts +93 -0
- package/dist/types/master/pool.d.ts.map +1 -0
- package/dist/types/master/register.d.ts +2 -0
- package/dist/types/master/register.d.ts.map +1 -0
- package/dist/{master → types/master}/spawn.d.ts +12 -2
- package/dist/types/master/spawn.d.ts.map +1 -0
- package/dist/types/master/thread.d.ts +13 -0
- package/dist/types/master/thread.d.ts.map +1 -0
- package/dist/{observable-promise.d.ts → types/observable-promise.d.ts} +14 -0
- package/dist/types/observable-promise.d.ts.map +1 -0
- package/dist/types/observable.d.ts +21 -0
- package/dist/types/observable.d.ts.map +1 -0
- package/dist/{ponyfills.d.ts → types/ponyfills.d.ts} +1 -0
- package/dist/types/ponyfills.d.ts.map +1 -0
- package/dist/types/promise.d.ts +6 -0
- package/dist/types/promise.d.ts.map +1 -0
- package/dist/{serializers.d.ts → types/serializers.d.ts} +1 -0
- package/dist/types/serializers.d.ts.map +1 -0
- package/dist/{symbols.d.ts → types/symbols.d.ts} +1 -0
- package/dist/types/symbols.d.ts.map +1 -0
- package/dist/types/transferable.d.ts +43 -0
- package/dist/types/transferable.d.ts.map +1 -0
- package/dist/types/{master.d.ts → types/master.d.ts} +17 -3
- package/dist/types/types/master.d.ts.map +1 -0
- package/dist/types/{messages.d.ts → types/messages.d.ts} +1 -0
- package/dist/types/types/messages.d.ts.map +1 -0
- package/dist/types/{worker.d.ts → types/worker.d.ts} +1 -0
- package/dist/types/types/worker.d.ts.map +1 -0
- package/dist/types/worker/WorkerGlobalScope.d.ts +6 -0
- package/dist/types/worker/WorkerGlobalScope.d.ts.map +1 -0
- package/dist/types/worker/expose.d.ts +4 -0
- package/dist/types/worker/expose.d.ts.map +1 -0
- package/dist/types/worker/worker.browser.d.ts +14 -0
- package/dist/types/worker/worker.browser.d.ts.map +1 -0
- package/dist/types/worker/worker.node.d.ts +25 -0
- package/dist/types/worker/worker.node.d.ts.map +1 -0
- package/package.json +66 -77
- package/src/common.ts +10 -6
- package/src/index.ts +10 -9
- package/src/master/get-bundle-url.browser.ts +2 -1
- package/src/master/implementation.browser.ts +2 -2
- package/src/master/implementation.node.ts +19 -96
- package/src/master/implementation.ts +2 -2
- package/src/master/index.ts +7 -7
- package/src/master/invocation-proxy.ts +6 -6
- package/src/master/pool-types.ts +1 -1
- package/src/master/pool.ts +14 -13
- package/src/master/register.ts +2 -1
- package/src/master/spawn.ts +8 -8
- package/src/master/thread.ts +2 -2
- package/src/observable-promise.ts +3 -2
- package/src/serializers.ts +1 -1
- package/src/transferable.ts +2 -1
- package/src/types/master.ts +3 -3
- package/src/worker/WorkerGlobalScope.ts +5 -0
- package/src/worker/expose.ts +234 -0
- package/src/worker/is-observable.d.ts +7 -0
- package/src/worker/{implementation.browser.ts → worker.browser.ts} +26 -10
- package/src/worker/{implementation.worker_threads.ts → worker.node.ts} +30 -12
- package/types/is-observable.d.ts +1 -1
- package/xy.config.ts +24 -0
- package/dist/common.js +0 -16
- package/dist/esm/common.js +0 -16
- package/dist/esm/index.js +0 -26
- package/dist/esm/master/get-bundle-url.browser.js +0 -25
- package/dist/esm/master/implementation.browser.js +0 -65
- package/dist/esm/master/implementation.js +0 -43
- package/dist/esm/master/implementation.node.js +0 -205
- package/dist/esm/master/index.js +0 -14
- package/dist/esm/master/invocation-proxy.js +0 -121
- package/dist/esm/master/pool-types.js +0 -14
- package/dist/esm/master/pool.js +0 -262
- package/dist/esm/master/register.js +0 -11
- package/dist/esm/master/spawn.js +0 -114
- package/dist/esm/master/thread.js +0 -18
- package/dist/esm/observable-promise.js +0 -132
- package/dist/esm/observable.js +0 -33
- package/dist/esm/ponyfills.js +0 -20
- package/dist/esm/promise.js +0 -23
- package/dist/esm/serializers.js +0 -41
- package/dist/esm/symbols.js +0 -8
- package/dist/esm/transferable.js +0 -25
- package/dist/esm/types/master.js +0 -9
- package/dist/esm/types/messages.js +0 -16
- package/dist/esm/types/worker.js +0 -2
- package/dist/esm/worker/bundle-entry.js +0 -26
- package/dist/esm/worker/implementation.browser.js +0 -24
- package/dist/esm/worker/implementation.js +0 -19
- package/dist/esm/worker/implementation.tiny-worker.js +0 -37
- package/dist/esm/worker/implementation.worker_threads.js +0 -41
- package/dist/esm/worker/index.js +0 -174
- package/dist/esm/worker_threads.js +0 -13
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -26
- package/dist/master/get-bundle-url.browser.js +0 -25
- package/dist/master/implementation.browser.js +0 -65
- package/dist/master/implementation.js +0 -43
- package/dist/master/implementation.node.js +0 -205
- package/dist/master/index.d.ts +0 -10
- package/dist/master/index.js +0 -14
- package/dist/master/invocation-proxy.js +0 -121
- package/dist/master/pool-types.js +0 -14
- package/dist/master/pool.d.ts +0 -50
- package/dist/master/pool.js +0 -262
- package/dist/master/register.d.ts +0 -1
- package/dist/master/register.js +0 -11
- package/dist/master/spawn.js +0 -114
- package/dist/master/thread.d.ts +0 -8
- package/dist/master/thread.js +0 -18
- package/dist/observable-promise.js +0 -132
- package/dist/observable.d.ts +0 -11
- package/dist/observable.js +0 -33
- package/dist/ponyfills.js +0 -20
- package/dist/promise.d.ts +0 -1
- package/dist/promise.js +0 -23
- package/dist/serializers.js +0 -41
- package/dist/symbols.js +0 -8
- package/dist/transferable.d.ts +0 -9
- package/dist/transferable.js +0 -25
- package/dist/types/master.js +0 -9
- package/dist/types/messages.js +0 -16
- package/dist/types/worker.js +0 -2
- package/dist/worker/bundle-entry.d.ts +0 -1
- package/dist/worker/bundle-entry.js +0 -26
- package/dist/worker/implementation.browser.d.ts +0 -6
- package/dist/worker/implementation.browser.js +0 -24
- package/dist/worker/implementation.d.ts +0 -3
- package/dist/worker/implementation.js +0 -19
- package/dist/worker/implementation.tiny-worker.d.ts +0 -6
- package/dist/worker/implementation.tiny-worker.js +0 -37
- package/dist/worker/implementation.worker_threads.d.ts +0 -8
- package/dist/worker/implementation.worker_threads.js +0 -41
- package/dist/worker/index.d.ts +0 -5
- package/dist/worker/index.js +0 -174
- package/dist/worker_threads.d.ts +0 -8
- package/dist/worker_threads.js +0 -13
- package/observable.d.ts +0 -2
- package/observable.js +0 -2
- package/observable.mjs +0 -4
- package/register.d.ts +0 -2
- package/register.js +0 -2
- package/register.mjs +0 -1
- package/rollup.config.js +0 -16
- package/src/worker/bundle-entry.ts +0 -10
- package/src/worker/implementation.tiny-worker.ts +0 -55
- package/src/worker/implementation.ts +0 -23
- package/src/worker/index.ts +0 -230
- package/src/worker_threads.ts +0 -27
- package/test/lib/index.ts +0 -1
- package/test/lib/serialization.ts +0 -38
- package/test/observable-promise.test.ts +0 -205
- package/test/observable.test.ts +0 -87
- package/test/pool.test.ts +0 -183
- package/test/serialization.test.ts +0 -23
- package/test/spawn.chromium.mocha.ts +0 -53
- package/test/spawn.test.ts +0 -87
- package/test/streaming.test.ts +0 -29
- package/test/transferables.test.ts +0 -71
- package/test/workers/arraybuffer-xor.ts +0 -10
- package/test/workers/count-to-five.ts +0 -12
- package/test/workers/counter.ts +0 -19
- package/test/workers/faulty-function.ts +0 -5
- package/test/workers/hello-world.ts +0 -5
- package/test/workers/increment.ts +0 -8
- package/test/workers/minmax.ts +0 -25
- package/test/workers/serialization.ts +0 -13
- package/test/workers/top-level-throw.ts +0 -1
- package/test-tooling/rollup/app.js +0 -21
- package/test-tooling/rollup/rollup.config.ts +0 -14
- package/test-tooling/rollup/worker.js +0 -7
- package/test-tooling/tsconfig/minimal.ts +0 -12
- package/test-tooling/webpack/addition-worker.ts +0 -9
- package/test-tooling/webpack/app-with-inlined-worker.ts +0 -28
- package/test-tooling/webpack/app.ts +0 -61
- package/test-tooling/webpack/pool-worker.ts +0 -5
- package/test-tooling/webpack/raw-loader.d.ts +0 -4
- package/test-tooling/webpack/webpack.chromium.mocha.ts +0 -21
- package/test-tooling/webpack/webpack.node.config.js +0 -29
- package/test-tooling/webpack/webpack.web.config.js +0 -28
- package/types/webworker.d.ts +0 -9
- package/worker.d.ts +0 -2
- package/worker.js +0 -2
- package/worker.mjs +0 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/threads",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "Web workers & worker threads as simple as a function call",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"thread",
|
|
@@ -29,85 +29,88 @@
|
|
|
29
29
|
"./register.*js",
|
|
30
30
|
"./worker.*js"
|
|
31
31
|
],
|
|
32
|
+
"type": "module",
|
|
32
33
|
"exports": {
|
|
33
34
|
".": {
|
|
34
|
-
"types": "./dist/index.d.ts",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
35
|
+
"types": "./dist/types/index.d.ts",
|
|
36
|
+
"import": "./dist/neutral/index.mjs",
|
|
37
|
+
"default": "./dist/neutral/index.mjs"
|
|
38
|
+
},
|
|
39
|
+
"./implementation": {
|
|
40
|
+
"browser": {
|
|
41
|
+
"types": "./dist/types/master/implementation.browser.d.ts",
|
|
42
|
+
"import": "./dist/browser/master/implementation.browser.mjs",
|
|
43
|
+
"default": "./dist/browser/master/implementation.browser.mjs"
|
|
44
|
+
},
|
|
45
|
+
"node": {
|
|
46
|
+
"types": "./dist/types/master/implementation.node.d.ts",
|
|
47
|
+
"import": "./dist/node/master/implementation.node.mjs",
|
|
48
|
+
"default": "./dist/node/master/implementation.node.mjs"
|
|
49
|
+
},
|
|
50
|
+
"types": "./dist/types/master/implementation.d.ts",
|
|
51
|
+
"import": "./dist/neutral/master/implementation.mjs",
|
|
52
|
+
"default": "./dist/neutral/master/implementation.mjs"
|
|
38
53
|
},
|
|
39
54
|
"./master": {
|
|
40
|
-
"types": "./dist/types/master.d.ts",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
55
|
+
"types": "./dist/types/master/index.d.ts",
|
|
56
|
+
"import": "./dist/neutral/master/index.mjs",
|
|
57
|
+
"default": "./dist/neutral/master/index.mjs"
|
|
58
|
+
},
|
|
59
|
+
"./spawn": {
|
|
60
|
+
"types": "./dist/types/master/spawn.d.ts",
|
|
61
|
+
"import": "./dist/neutral/master/spawn.mjs",
|
|
62
|
+
"default": "./dist/neutral/master/spawn.mjs"
|
|
63
|
+
},
|
|
64
|
+
"./thread": {
|
|
65
|
+
"types": "./dist/types/master/thread.d.ts",
|
|
66
|
+
"import": "./dist/neutral/master/thread.mjs",
|
|
67
|
+
"default": "./dist/neutral/master/thread.mjs"
|
|
44
68
|
},
|
|
45
69
|
"./messenger": {
|
|
46
|
-
"types": "./dist/types/
|
|
70
|
+
"types": "./dist/types/types/messages.d.ts"
|
|
47
71
|
},
|
|
48
72
|
"./observable": {
|
|
49
|
-
"types": "./dist/observable.d.ts",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
|
|
73
|
+
"types": "./dist/types/observable.d.ts",
|
|
74
|
+
"import": "./dist/neutral/observable.mjs",
|
|
75
|
+
"default": "./dist/neutral/observable.mjs"
|
|
76
|
+
},
|
|
77
|
+
"./pool": {
|
|
78
|
+
"types": "./dist/types/master/pool.d.ts",
|
|
79
|
+
"import": "./dist/neutral/master/pool.mjs",
|
|
80
|
+
"default": "./dist/neutral/master/pool.mjs"
|
|
81
|
+
},
|
|
82
|
+
"./observable-promise": {
|
|
83
|
+
"types": "./dist/types/observable-promise.d.ts",
|
|
84
|
+
"import": "./dist/neutral/observable-promise.mjs",
|
|
85
|
+
"default": "./dist/neutral/observable-promise.mjs"
|
|
53
86
|
},
|
|
54
87
|
"./register": {
|
|
55
|
-
"types": "./dist/master/register.d.ts",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"default": "./dist/esm/master/register/index.js"
|
|
88
|
+
"types": "./dist/types/master/register.d.ts",
|
|
89
|
+
"import": "./dist/neutral/master/register.mjs",
|
|
90
|
+
"default": "./dist/neutral/master/register.mjs"
|
|
59
91
|
},
|
|
60
92
|
"./worker": {
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
93
|
+
"browser": {
|
|
94
|
+
"types": "./dist/types/worker/worker.browser.d.ts",
|
|
95
|
+
"import": "./dist/browser/worker/worker.browser.mjs",
|
|
96
|
+
"default": "./dist/browser/worker/worker.browser.mjs"
|
|
97
|
+
},
|
|
98
|
+
"node": {
|
|
99
|
+
"types": "./dist/types/worker/worker.node.d.ts",
|
|
100
|
+
"import": "./dist/node/worker/worker.node.mjs",
|
|
101
|
+
"default": "./dist/node/worker/worker.node.mjs"
|
|
102
|
+
}
|
|
65
103
|
}
|
|
66
104
|
},
|
|
67
|
-
"main": "dist/index.
|
|
68
|
-
"module": "dist/
|
|
69
|
-
"
|
|
70
|
-
"./dist/esm/master/implementation.js": "./dist/esm/master/implementation.browser.js",
|
|
71
|
-
"./dist/esm/master/implementation.node.js": false,
|
|
72
|
-
"./dist/esm/worker/implementation.js": "./dist/esm/worker/implementation.browser.js",
|
|
73
|
-
"./dist/esm/worker/implementation.tiny-worker.js": false,
|
|
74
|
-
"./dist/esm/worker/implementation.worker_threads.js": false,
|
|
75
|
-
"./dist/master/implementation.js": "./dist/master/implementation.browser.js",
|
|
76
|
-
"./dist/master/implementation.node.js": false,
|
|
77
|
-
"./dist/worker/implementation.js": "./dist/worker/implementation.browser.js",
|
|
78
|
-
"./dist/worker/implementation.tiny-worker.js": false,
|
|
79
|
-
"./dist/worker/implementation.worker_threads.js": false,
|
|
80
|
-
"callsites": false,
|
|
81
|
-
"tiny-worker": false,
|
|
82
|
-
"ts-node": false,
|
|
83
|
-
"ts-node/register": false,
|
|
84
|
-
"worker_threads": false
|
|
85
|
-
},
|
|
86
|
-
"types": "dist/index.d.ts",
|
|
105
|
+
"main": "dist/neutral/index.mjs",
|
|
106
|
+
"module": "dist/neutral/index.mjs",
|
|
107
|
+
"types": "dist/types/index.d.ts",
|
|
87
108
|
"files": [
|
|
88
109
|
"dist/**",
|
|
89
110
|
"*.js",
|
|
90
111
|
"*.mjs",
|
|
91
112
|
"*.ts"
|
|
92
113
|
],
|
|
93
|
-
"scripts": {
|
|
94
|
-
"build-threads": "yarn clean && yarn build:cjs && yarn build:es",
|
|
95
|
-
"build:cjs": "tsc -p tsconfig.json",
|
|
96
|
-
"build:es": "tsc -p tsconfig-esm.json",
|
|
97
|
-
"bundle": "rollup -c -f umd --file=bundle/worker.js --name=threads --silent -- dist/esm/worker/bundle-entry.js",
|
|
98
|
-
"clean": "rimraf ./dist ./dist-esm",
|
|
99
|
-
"dev": "yarn clean && tsc -p tsconfig.json --watch",
|
|
100
|
-
"package-build": "echo BUILD && yarn build-threads && echo BUILD_DONE",
|
|
101
|
-
"package-compile": "echo COMPILE && yarn build-threads && echo COMPILE_DONE",
|
|
102
|
-
"package-publint": "echo Skipping Publint - @xylabs/threads",
|
|
103
|
-
"postbuild": "yarn bundle",
|
|
104
|
-
"prepare": "yarn build-threads",
|
|
105
|
-
"test": "yarn test:library && yarn test:tooling && yarn test:puppeteer:basic && yarn test:puppeteer:webpack",
|
|
106
|
-
"test:library": "cross-env TS_NODE_FILES=true vitest ./test/**/*.test.ts",
|
|
107
|
-
"test:puppeteer:basic": "puppet-run --plugin=mocha --bundle=./test/workers/:workers/ --serve=./bundle/worker.js:/worker.js ./test/*.chromium*.ts",
|
|
108
|
-
"test:puppeteer:webpack": "puppet-run --serve ./test-tooling/webpack/dist/app.web/0.worker.js --serve ./test-tooling/webpack/dist/app.web/1.worker.js --plugin=mocha ./test-tooling/webpack/webpack.chromium.mocha.ts",
|
|
109
|
-
"test:tooling": "cross-env TS_NODE_FILES=true vitest ./test-tooling/**/*.test.ts"
|
|
110
|
-
},
|
|
111
114
|
"ava": {
|
|
112
115
|
"extensions": [
|
|
113
116
|
"ts"
|
|
@@ -122,30 +125,16 @@
|
|
|
122
125
|
"serial": true
|
|
123
126
|
},
|
|
124
127
|
"dependencies": {
|
|
125
|
-
"callsites-3-1-0": "npm:callsites@3.1.0",
|
|
126
128
|
"debug": "^4.4.0",
|
|
127
129
|
"is-observable-2-1-0": "npm:is-observable@2.1.0",
|
|
128
130
|
"observable-fns": "^0.6.1"
|
|
129
131
|
},
|
|
130
132
|
"devDependencies": {
|
|
131
|
-
"@babel/types": "^7.26.10",
|
|
132
|
-
"@rollup/plugin-commonjs": "^28.0.3",
|
|
133
|
-
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
134
133
|
"@types/debug": "^4.1.12",
|
|
135
134
|
"@types/node": "^22.13.10",
|
|
136
|
-
"@xylabs/eslint-config-flat": "^6.1.
|
|
137
|
-
"@xylabs/ts-scripts-yarn3": "^6.1.
|
|
138
|
-
"
|
|
139
|
-
"puppet-run": "^0.11.4",
|
|
140
|
-
"raw-loader": "^4.0.2",
|
|
141
|
-
"rimraf": "^6.0.1",
|
|
142
|
-
"rollup": "^4.36.0",
|
|
143
|
-
"threads-plugin": "^1.4.0",
|
|
144
|
-
"tiny-worker": "^2.3.0",
|
|
145
|
-
"tslib": "^2.8.1",
|
|
146
|
-
"typescript": "^5.8.2",
|
|
147
|
-
"vitest": "^3.0.9",
|
|
148
|
-
"webpack": "^5.98.0"
|
|
135
|
+
"@xylabs/eslint-config-flat": "^6.1.4",
|
|
136
|
+
"@xylabs/ts-scripts-yarn3": "^6.1.4",
|
|
137
|
+
"typescript": "^5.8.2"
|
|
149
138
|
},
|
|
150
139
|
"optionalDependencies": {
|
|
151
140
|
"tiny-worker": "^2.3.0"
|
package/src/common.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import type {
|
|
3
3
|
JsonSerializable, Serializer, SerializerImplementation,
|
|
4
|
-
} from './serializers'
|
|
5
|
-
import { DefaultSerializer, extendSerializer } from './serializers'
|
|
4
|
+
} from './serializers.ts'
|
|
5
|
+
import { DefaultSerializer, extendSerializer } from './serializers.ts'
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
declare global {
|
|
8
|
+
var registeredSerializer: Serializer<JsonSerializable>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
globalThis.registeredSerializer = globalThis.registeredSerializer ?? DefaultSerializer
|
|
8
12
|
|
|
9
13
|
export function registerSerializer(serializer: SerializerImplementation<JsonSerializable>) {
|
|
10
|
-
registeredSerializer = extendSerializer(registeredSerializer, serializer)
|
|
14
|
+
globalThis.registeredSerializer = extendSerializer(globalThis.registeredSerializer, serializer)
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
export function deserialize(message: JsonSerializable): any {
|
|
14
|
-
return registeredSerializer.deserialize(message)
|
|
18
|
+
return globalThis.registeredSerializer.deserialize(message)
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
export function serialize(input: any): JsonSerializable {
|
|
18
|
-
return registeredSerializer.serialize(input)
|
|
22
|
+
return globalThis.registeredSerializer.serialize(input)
|
|
19
23
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/* eslint-disable import-x/no-internal-modules */
|
|
2
|
-
export { registerSerializer } from './common'
|
|
3
|
-
export * from './master/index'
|
|
4
|
-
export { QueuedTask } from './master/pool'
|
|
5
|
-
export { ExposedToThreadType as ExposedAs } from './master/spawn'
|
|
6
|
-
export {
|
|
7
|
-
|
|
8
|
-
} from './serializers'
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
2
|
+
export { registerSerializer } from './common.ts'
|
|
3
|
+
export * from './master/index.ts'
|
|
4
|
+
export type { QueuedTask } from './master/pool.ts'
|
|
5
|
+
export type { ExposedToThreadType as ExposedAs } from './master/spawn.ts'
|
|
6
|
+
export type {
|
|
7
|
+
JsonSerializable, Serializer, SerializerImplementation,
|
|
8
|
+
} from './serializers.ts'
|
|
9
|
+
export { DefaultSerializer } from './serializers.ts'
|
|
10
|
+
export type { TransferDescriptor } from './transferable.ts'
|
|
11
|
+
export { Transfer } from './transferable.ts'
|
|
@@ -14,7 +14,8 @@ function getBundleURL(): string {
|
|
|
14
14
|
// Attempt to find the URL of the current script and use that as the base URL
|
|
15
15
|
try {
|
|
16
16
|
throw new Error('getBundleURL failed')
|
|
17
|
-
} catch (
|
|
17
|
+
} catch (ex) {
|
|
18
|
+
const err = ex as Error
|
|
18
19
|
const matches = ('' + err.stack).match(/(https?|file|ftp|chrome-extension|moz-extension):\/\/[^\n)]+/g)
|
|
19
20
|
if (matches) {
|
|
20
21
|
return getBaseURL(matches[0])
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
/* eslint-disable import-x/no-internal-modules */
|
|
3
3
|
// tslint:disable max-classes-per-file
|
|
4
4
|
|
|
5
|
-
import type { ImplementationExport, ThreadsWorkerOptions } from '../types/master'
|
|
6
|
-
import { getBundleURL } from './get-bundle-url.browser'
|
|
5
|
+
import type { ImplementationExport, ThreadsWorkerOptions } from '../types/master.ts'
|
|
6
|
+
import { getBundleURL } from './get-bundle-url.browser.ts'
|
|
7
7
|
|
|
8
8
|
export const defaultPoolSize = typeof navigator !== 'undefined' && navigator.hardwareConcurrency ? navigator.hardwareConcurrency : 4
|
|
9
9
|
|
|
@@ -1,123 +1,50 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
2
|
-
/* eslint-disable import-x/no-internal-modules */
|
|
3
|
-
/* eslint-disable unicorn/no-process-exit */
|
|
4
|
-
/* eslint-disable unicorn/prefer-logical-operator-over-ternary */
|
|
5
|
-
/* eslint-disable unicorn/prefer-regexp-test */
|
|
6
2
|
|
|
7
3
|
/* eslint-disable unicorn/prefer-add-event-listener */
|
|
8
4
|
/* eslint-disable unicorn/prefer-event-target */
|
|
9
5
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
10
6
|
/* eslint-disable unicorn/text-encoding-identifier-case */
|
|
11
|
-
/// <reference lib="dom" />
|
|
12
7
|
|
|
13
8
|
import { EventEmitter } from 'node:events'
|
|
14
9
|
import { cpus } from 'node:os'
|
|
15
10
|
import path from 'node:path'
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
import type { CallSite } from 'callsites-3-1-0'
|
|
19
|
-
import getCallsites from 'callsites-3-1-0'
|
|
11
|
+
import { cwd } from 'node:process'
|
|
12
|
+
import { Worker as NativeWorker } from 'node:worker_threads'
|
|
20
13
|
|
|
21
14
|
import type {
|
|
22
15
|
ImplementationExport, ThreadsWorkerOptions, WorkerImplementation,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
interface WorkerGlobalScope {
|
|
26
|
-
addEventListener(eventName: string, listener: (event: Event) => void): void
|
|
27
|
-
postMessage(message: any, transferables?: any[]): void
|
|
28
|
-
removeEventListener(eventName: string, listener: (event: Event) => void): void
|
|
29
|
-
}
|
|
16
|
+
// eslint-disable-next-line import-x/no-internal-modules
|
|
17
|
+
} from '../types/master.ts'
|
|
30
18
|
|
|
31
19
|
declare const __non_webpack_require__: typeof require
|
|
32
|
-
declare const self: WorkerGlobalScope
|
|
33
20
|
|
|
34
21
|
type WorkerEventName = 'error' | 'message'
|
|
35
22
|
|
|
36
|
-
let tsNodeAvailable: boolean | undefined
|
|
37
|
-
|
|
38
23
|
export const defaultPoolSize = cpus().length
|
|
39
24
|
|
|
40
|
-
function detectTsNode() {
|
|
41
|
-
if (typeof __non_webpack_require__ === 'function') {
|
|
42
|
-
// Webpack build: => No ts-node required or possible
|
|
43
|
-
return false
|
|
44
|
-
}
|
|
45
|
-
if (tsNodeAvailable) {
|
|
46
|
-
return tsNodeAvailable
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
eval('require').resolve('ts-node')
|
|
51
|
-
tsNodeAvailable = true
|
|
52
|
-
} catch (error) {
|
|
53
|
-
if (error && error.code === 'MODULE_NOT_FOUND') {
|
|
54
|
-
tsNodeAvailable = false
|
|
55
|
-
} else {
|
|
56
|
-
// Re-throw
|
|
57
|
-
throw error
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return tsNodeAvailable
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function createTsNodeModule(scriptPath: string) {
|
|
64
|
-
return `
|
|
65
|
-
require("ts-node/register/transpile-only");
|
|
66
|
-
require(${JSON.stringify(scriptPath)});
|
|
67
|
-
`
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function rebaseScriptPath(scriptPath: string, ignoreRegex: RegExp) {
|
|
71
|
-
const parentCallSite = getCallsites().find((callsite: CallSite) => {
|
|
72
|
-
const filename = callsite.getFileName()
|
|
73
|
-
return Boolean(
|
|
74
|
-
filename && !filename.match(ignoreRegex) && !/[/\\]master[/\\]implementation/.test(filename) && !/^internal\/process/.test(filename),
|
|
75
|
-
)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
const rawCallerPath = parentCallSite ? parentCallSite.getFileName() : null
|
|
79
|
-
let callerPath = rawCallerPath ? rawCallerPath : null
|
|
80
|
-
if (callerPath && callerPath.startsWith('file:')) {
|
|
81
|
-
callerPath = fileURLToPath(callerPath)
|
|
82
|
-
}
|
|
83
|
-
return callerPath ? path.join(path.dirname(callerPath), scriptPath) : scriptPath
|
|
84
|
-
}
|
|
85
|
-
|
|
86
25
|
function resolveScriptPath(scriptPath: string, baseURL?: string | undefined) {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
return path.isAbsolute(filePath) ? filePath : path.join(baseURL || eval('__dirname'), filePath)
|
|
26
|
+
const makeAbsolute = (filePath: string) => {
|
|
27
|
+
return path.isAbsolute(filePath) ? filePath : path.join(baseURL ?? cwd(), filePath)
|
|
90
28
|
}
|
|
91
29
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
: eval('require').resolve(makeRelative(rebaseScriptPath(scriptPath, /[/\\]worker_threads[/\\]/)))
|
|
30
|
+
const absolutePath = makeAbsolute(scriptPath)
|
|
31
|
+
return absolutePath
|
|
95
32
|
}
|
|
96
33
|
|
|
97
34
|
function initWorkerThreadsWorker(): ImplementationExport {
|
|
98
|
-
|
|
99
|
-
const NativeWorker
|
|
100
|
-
= typeof __non_webpack_require__ === 'function' ? __non_webpack_require__('worker_threads').Worker : eval('require')('worker_threads').Worker
|
|
101
|
-
|
|
102
|
-
let allWorkers: Array<typeof NativeWorker> = []
|
|
35
|
+
let allWorkers: Array<NativeWorker> = []
|
|
103
36
|
|
|
104
37
|
class Worker extends NativeWorker {
|
|
105
38
|
private mappedEventListeners: WeakMap<EventListener, EventListener>
|
|
106
39
|
|
|
107
40
|
constructor(scriptPath: string, options?: ThreadsWorkerOptions & { fromSource: boolean }) {
|
|
108
|
-
const resolvedScriptPath = options && options.fromSource ? null : resolveScriptPath(scriptPath, (options
|
|
109
|
-
|
|
110
|
-
|
|
41
|
+
const resolvedScriptPath = options && options.fromSource ? null : resolveScriptPath(scriptPath, (options ?? {})._baseURL)
|
|
42
|
+
if (resolvedScriptPath) {
|
|
43
|
+
super(resolvedScriptPath, options)
|
|
44
|
+
} else {
|
|
111
45
|
// `options.fromSource` is true
|
|
112
46
|
const sourceCode = scriptPath
|
|
113
47
|
super(sourceCode, { ...options, eval: true })
|
|
114
|
-
} else if (/\.tsx?$/i.test(resolvedScriptPath) && detectTsNode()) {
|
|
115
|
-
super(createTsNodeModule(resolvedScriptPath), { ...options, eval: true })
|
|
116
|
-
} else if (/\.asar[/\\]/.test(resolvedScriptPath)) {
|
|
117
|
-
// See <https://github.com/andywer/threads-plugin/issues/17>
|
|
118
|
-
super(resolvedScriptPath.replace(/\.asar([/\\])/, '.asar.unpacked$1'), options)
|
|
119
|
-
} else {
|
|
120
|
-
super(resolvedScriptPath, options)
|
|
121
48
|
}
|
|
122
49
|
|
|
123
50
|
this.mappedEventListeners = new WeakMap()
|
|
@@ -185,17 +112,12 @@ function initTinyWorker(): ImplementationExport {
|
|
|
185
112
|
? `file:///${resolveScriptPath(scriptPath).replaceAll('\\', '/')}`
|
|
186
113
|
: resolveScriptPath(scriptPath)
|
|
187
114
|
|
|
188
|
-
if (
|
|
115
|
+
if (resolvedScriptPath) {
|
|
116
|
+
super(resolvedScriptPath, [], { esm: true })
|
|
117
|
+
} else {
|
|
189
118
|
// `options.fromSource` is true
|
|
190
119
|
const sourceCode = scriptPath
|
|
191
120
|
super(new Function(sourceCode), [], { esm: true })
|
|
192
|
-
} else if (/\.tsx?$/i.test(resolvedScriptPath) && detectTsNode()) {
|
|
193
|
-
super(new Function(createTsNodeModule(resolveScriptPath(scriptPath))), [], { esm: true })
|
|
194
|
-
} else if (/\.asar[/\\]/.test(resolvedScriptPath)) {
|
|
195
|
-
// See <https://github.com/andywer/threads-plugin/issues/17>
|
|
196
|
-
super(resolvedScriptPath.replace(/\.asar([/\\])/, '.asar.unpacked$1'), [], { esm: true })
|
|
197
|
-
} else {
|
|
198
|
-
super(resolvedScriptPath, [], { esm: true })
|
|
199
121
|
}
|
|
200
122
|
|
|
201
123
|
allWorkers.push(this)
|
|
@@ -256,7 +178,8 @@ function selectWorkerImplementation(): ImplementationExport {
|
|
|
256
178
|
try {
|
|
257
179
|
isTinyWorker = false
|
|
258
180
|
return initWorkerThreadsWorker()
|
|
259
|
-
} catch {
|
|
181
|
+
} catch (ex) {
|
|
182
|
+
console.error(ex)
|
|
260
183
|
// tslint:disable-next-line no-console
|
|
261
184
|
console.debug('Node worker_threads not available. Trying to fall back to tiny-worker polyfill...')
|
|
262
185
|
isTinyWorker = true
|
|
@@ -273,7 +196,7 @@ export function getWorkerImplementation(): ImplementationExport {
|
|
|
273
196
|
|
|
274
197
|
export function isWorkerRuntime() {
|
|
275
198
|
if (isTinyWorker) {
|
|
276
|
-
return
|
|
199
|
+
return globalThis !== undefined && self['postMessage'] ? true : false
|
|
277
200
|
} else {
|
|
278
201
|
// Webpack hack
|
|
279
202
|
const isMainThread
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
// browsers already in the package.json, so if get here, it's safe to pass-through the
|
|
7
7
|
// node implementation
|
|
8
8
|
|
|
9
|
-
import * as BrowserImplementation from './implementation.browser'
|
|
10
|
-
import * as NodeImplementation from './implementation.node'
|
|
9
|
+
import * as BrowserImplementation from './implementation.browser.ts'
|
|
10
|
+
import * as NodeImplementation from './implementation.node.ts'
|
|
11
11
|
|
|
12
12
|
const runningInNode = typeof process !== 'undefined' && (process.arch as string) !== 'browser' && 'pid' in process
|
|
13
13
|
const implementation = runningInNode ? NodeImplementation : BrowserImplementation
|
package/src/master/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* eslint-disable import-x/no-internal-modules */
|
|
2
|
-
import type { BlobWorker as BlobWorkerClass, Worker as WorkerType } from '../types/master'
|
|
3
|
-
import { getWorkerImplementation } from './implementation'
|
|
2
|
+
import type { BlobWorker as BlobWorkerClass, Worker as WorkerType } from '../types/master.ts'
|
|
3
|
+
import { getWorkerImplementation } from './implementation.ts'
|
|
4
4
|
|
|
5
|
-
export { FunctionThread, ModuleThread } from '../types/master'
|
|
6
|
-
export { Pool } from './pool'
|
|
7
|
-
export { spawn } from './spawn'
|
|
8
|
-
export { Thread } from './thread'
|
|
5
|
+
export type { FunctionThread, ModuleThread } from '../types/master.ts'
|
|
6
|
+
export { Pool } from './pool.ts'
|
|
7
|
+
export { spawn } from './spawn.ts'
|
|
8
|
+
export { Thread } from './thread.ts'
|
|
9
9
|
|
|
10
10
|
export type BlobWorker = typeof BlobWorkerClass
|
|
11
11
|
export type Worker = WorkerType
|
|
@@ -16,4 +16,4 @@ export const BlobWorker = getWorkerImplementation().blob
|
|
|
16
16
|
/** Worker implementation. Either web worker or a node.js Worker class. */
|
|
17
17
|
export const Worker = getWorkerImplementation().default
|
|
18
18
|
|
|
19
|
-
export { isWorkerRuntime } from './implementation'
|
|
19
|
+
export { isWorkerRuntime } from './implementation.ts'
|
|
@@ -10,23 +10,23 @@
|
|
|
10
10
|
import DebugLogger from 'debug'
|
|
11
11
|
import { multicast, Observable } from 'observable-fns'
|
|
12
12
|
|
|
13
|
-
import { deserialize, serialize } from '../common'
|
|
14
|
-
import { ObservablePromise } from '../observable-promise'
|
|
15
|
-
import { isTransferDescriptor } from '../transferable'
|
|
13
|
+
import { deserialize, serialize } from '../common.ts'
|
|
14
|
+
import { ObservablePromise } from '../observable-promise.ts'
|
|
15
|
+
import { isTransferDescriptor } from '../transferable.ts'
|
|
16
16
|
import type {
|
|
17
17
|
ModuleMethods, ModuleProxy, ProxyableFunction, Worker as WorkerType,
|
|
18
|
-
} from '../types/master'
|
|
18
|
+
} from '../types/master.ts'
|
|
19
19
|
import type {
|
|
20
20
|
MasterJobCancelMessage,
|
|
21
21
|
MasterJobRunMessage,
|
|
22
22
|
WorkerJobErrorMessage,
|
|
23
23
|
WorkerJobResultMessage,
|
|
24
24
|
WorkerJobStartMessage,
|
|
25
|
-
} from '../types/messages'
|
|
25
|
+
} from '../types/messages.ts'
|
|
26
26
|
import {
|
|
27
27
|
MasterMessageType,
|
|
28
28
|
WorkerMessageType,
|
|
29
|
-
} from '../types/messages'
|
|
29
|
+
} from '../types/messages.ts'
|
|
30
30
|
|
|
31
31
|
const debugMessages = DebugLogger('threads:master:messages')
|
|
32
32
|
|
package/src/master/pool-types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
/* eslint-disable @typescript-eslint/member-ordering */
|
|
3
|
-
import type { Thread } from './thread'
|
|
3
|
+
import type { Thread } from './thread.ts'
|
|
4
4
|
|
|
5
5
|
/** Pool event type. Specifies the type of each `PoolEvent`. */
|
|
6
6
|
export enum PoolEventType {
|
package/src/master/pool.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
/* eslint-disable import-x/export */
|
|
2
2
|
/* eslint-disable unicorn/no-thenable */
|
|
3
3
|
|
|
4
|
-
/* eslint-disable require-await */
|
|
5
4
|
/* eslint-disable @typescript-eslint/member-ordering */
|
|
6
5
|
/* eslint-disable unicorn/no-array-reduce */
|
|
7
6
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
7
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
/// <reference lib="esnext" />
|
|
10
|
+
|
|
10
11
|
import DebugLogger from 'debug'
|
|
11
12
|
import {
|
|
12
13
|
multicast, Observable, Subject,
|
|
13
14
|
} from 'observable-fns'
|
|
14
15
|
|
|
15
|
-
import { allSettled } from '../ponyfills'
|
|
16
|
-
import { defaultPoolSize } from './implementation'
|
|
16
|
+
import { allSettled } from '../ponyfills.ts'
|
|
17
|
+
import { defaultPoolSize } from './implementation.ts'
|
|
17
18
|
import type {
|
|
18
19
|
PoolEvent, QueuedTask, TaskRunFunction, WorkerDescriptor,
|
|
19
|
-
} from './pool-types'
|
|
20
|
-
import { PoolEventType } from './pool-types'
|
|
21
|
-
import { Thread } from './thread'
|
|
20
|
+
} from './pool-types.ts'
|
|
21
|
+
import { PoolEventType } from './pool-types.ts'
|
|
22
|
+
import { Thread } from './thread.ts'
|
|
22
23
|
|
|
23
24
|
export declare namespace Pool {
|
|
24
25
|
type Event<ThreadType extends Thread = any> = PoolEvent<ThreadType>
|
|
@@ -177,7 +178,8 @@ class WorkerPool<ThreadType extends Thread> implements Pool<ThreadType> {
|
|
|
177
178
|
type: PoolEventType.taskCompleted,
|
|
178
179
|
workerID,
|
|
179
180
|
})
|
|
180
|
-
} catch (
|
|
181
|
+
} catch (ex) {
|
|
182
|
+
const error = ex as Error
|
|
181
183
|
this.debug(`Task #${task.id} failed`)
|
|
182
184
|
this.eventSubject.next({
|
|
183
185
|
error,
|
|
@@ -188,7 +190,7 @@ class WorkerPool<ThreadType extends Thread> implements Pool<ThreadType> {
|
|
|
188
190
|
}
|
|
189
191
|
}
|
|
190
192
|
|
|
191
|
-
private
|
|
193
|
+
private run(worker: WorkerDescriptor<ThreadType>, task: QueuedTask<ThreadType, any>) {
|
|
192
194
|
const runPromise = (async () => {
|
|
193
195
|
const removeTaskFromWorkersRunningTasks = () => {
|
|
194
196
|
worker.runningTasks = worker.runningTasks.filter(someRunPromise => someRunPromise !== runPromise)
|
|
@@ -393,7 +395,6 @@ function PoolConstructor<ThreadType extends Thread>(spawnWorker: () => Promise<T
|
|
|
393
395
|
*/
|
|
394
396
|
export const Pool = PoolConstructor as typeof PoolConstructor & { EventType: typeof PoolEventType }
|
|
395
397
|
|
|
396
|
-
export {
|
|
397
|
-
|
|
398
|
-
} from './
|
|
399
|
-
export { Thread } from './thread'
|
|
398
|
+
export type { PoolEvent, QueuedTask } from './pool-types.ts'
|
|
399
|
+
export { PoolEventType } from './pool-types.ts'
|
|
400
|
+
export { Thread } from './thread.ts'
|
package/src/master/register.ts
CHANGED
package/src/master/spawn.ts
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
import DebugLogger from 'debug'
|
|
5
5
|
import { Observable } from 'observable-fns'
|
|
6
6
|
|
|
7
|
-
import { deserialize } from '../common'
|
|
8
|
-
import { createPromiseWithResolver } from '../promise'
|
|
7
|
+
import { deserialize } from '../common.ts'
|
|
8
|
+
import { createPromiseWithResolver } from '../promise.ts'
|
|
9
9
|
import {
|
|
10
10
|
$errors, $events, $terminate, $worker,
|
|
11
|
-
} from '../symbols'
|
|
11
|
+
} from '../symbols.ts'
|
|
12
12
|
import type {
|
|
13
13
|
FunctionThread,
|
|
14
14
|
ModuleThread,
|
|
@@ -19,11 +19,11 @@ import type {
|
|
|
19
19
|
WorkerInternalErrorEvent,
|
|
20
20
|
WorkerMessageEvent,
|
|
21
21
|
WorkerTerminationEvent,
|
|
22
|
-
} from '../types/master'
|
|
23
|
-
import { WorkerEventType } from '../types/master'
|
|
24
|
-
import type { WorkerInitMessage, WorkerUncaughtErrorMessage } from '../types/messages'
|
|
25
|
-
import type { WorkerFunction, WorkerModule } from '../types/worker'
|
|
26
|
-
import { createProxyFunction, createProxyModule } from './invocation-proxy'
|
|
22
|
+
} from '../types/master.ts'
|
|
23
|
+
import { WorkerEventType } from '../types/master.ts'
|
|
24
|
+
import type { WorkerInitMessage, WorkerUncaughtErrorMessage } from '../types/messages.ts'
|
|
25
|
+
import type { WorkerFunction, WorkerModule } from '../types/worker.ts'
|
|
26
|
+
import { createProxyFunction, createProxyModule } from './invocation-proxy.ts'
|
|
27
27
|
|
|
28
28
|
type ArbitraryWorkerInterface = WorkerFunction & WorkerModule<string> & { somekeythatisneverusedinproductioncode123: 'magicmarker123' }
|
|
29
29
|
type ArbitraryThreadType = FunctionThread<any, any> & ModuleThread<any>
|
package/src/master/thread.ts
CHANGED
|
@@ -3,8 +3,8 @@ import type { Observable } from 'observable-fns'
|
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
$errors, $events, $terminate,
|
|
6
|
-
} from '../symbols'
|
|
7
|
-
import type { Thread as ThreadType, WorkerEvent } from '../types/master'
|
|
6
|
+
} from '../symbols.ts'
|
|
7
|
+
import type { Thread as ThreadType, WorkerEvent } from '../types/master.ts'
|
|
8
8
|
|
|
9
9
|
function fail(message: string): never {
|
|
10
10
|
throw new Error(message)
|