@xylabs/threads 4.7.0-rc.1 → 4.7.1
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/{types/common.d.ts → common.d.ts} +1 -5
- package/dist/common.js +16 -0
- package/dist/esm/common.js +16 -0
- package/dist/esm/index.js +26 -0
- package/dist/esm/master/get-bundle-url.browser.js +25 -0
- package/dist/esm/master/implementation.browser.js +65 -0
- package/dist/esm/master/implementation.js +43 -0
- package/dist/esm/master/implementation.node.js +205 -0
- package/dist/esm/master/index.js +14 -0
- package/dist/esm/master/invocation-proxy.js +121 -0
- package/dist/esm/master/pool-types.js +14 -0
- package/dist/esm/master/pool.js +262 -0
- package/dist/esm/master/register.js +11 -0
- package/dist/esm/master/spawn.js +114 -0
- package/dist/esm/master/thread.js +18 -0
- package/dist/esm/observable-promise.js +132 -0
- package/dist/esm/observable.js +33 -0
- package/dist/esm/ponyfills.js +20 -0
- package/dist/esm/promise.js +23 -0
- package/dist/esm/serializers.js +41 -0
- package/dist/esm/symbols.js +8 -0
- package/dist/esm/transferable.js +25 -0
- package/dist/esm/types/master.js +9 -0
- package/dist/esm/types/messages.js +16 -0
- package/dist/esm/types/worker.js +2 -0
- package/dist/esm/worker/bundle-entry.js +26 -0
- package/dist/esm/worker/implementation.browser.js +24 -0
- package/dist/esm/worker/implementation.js +19 -0
- package/dist/esm/worker/implementation.tiny-worker.js +37 -0
- package/dist/esm/worker/implementation.worker_threads.js +41 -0
- package/dist/esm/worker/index.js +174 -0
- package/dist/esm/worker_threads.js +13 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +26 -0
- package/dist/{types/master → master}/get-bundle-url.browser.d.ts +0 -1
- package/dist/master/get-bundle-url.browser.js +25 -0
- package/dist/{types/master → master}/implementation.browser.d.ts +1 -2
- package/dist/master/implementation.browser.js +65 -0
- package/dist/{types/master → master}/implementation.d.ts +1 -4
- package/dist/master/implementation.js +43 -0
- package/dist/{types/master → master}/implementation.node.d.ts +1 -2
- package/dist/master/implementation.node.js +205 -0
- package/dist/master/index.d.ts +10 -0
- package/dist/master/index.js +14 -0
- package/dist/{types/master → master}/invocation-proxy.d.ts +1 -2
- package/dist/master/invocation-proxy.js +121 -0
- package/dist/{types/master → master}/pool-types.d.ts +1 -16
- package/dist/master/pool-types.js +14 -0
- package/dist/master/pool.d.ts +50 -0
- package/dist/master/pool.js +262 -0
- package/dist/master/register.d.ts +1 -0
- package/dist/master/register.js +11 -0
- package/dist/{types/master → master}/spawn.d.ts +2 -12
- package/dist/master/spawn.js +114 -0
- package/dist/master/thread.d.ts +8 -0
- package/dist/master/thread.js +18 -0
- package/dist/{types/observable-promise.d.ts → observable-promise.d.ts} +0 -14
- package/dist/observable-promise.js +132 -0
- package/dist/observable.d.ts +11 -0
- package/dist/observable.js +33 -0
- package/dist/{types/ponyfills.d.ts → ponyfills.d.ts} +0 -1
- package/dist/ponyfills.js +20 -0
- package/dist/promise.d.ts +1 -0
- package/dist/promise.js +23 -0
- package/dist/{types/serializers.d.ts → serializers.d.ts} +0 -1
- package/dist/serializers.js +41 -0
- package/dist/{types/symbols.d.ts → symbols.d.ts} +0 -1
- package/dist/symbols.js +8 -0
- package/dist/transferable.d.ts +9 -0
- package/dist/transferable.js +25 -0
- package/dist/types/{types/master.d.ts → master.d.ts} +3 -17
- package/dist/types/master.js +9 -0
- package/dist/types/{types/messages.d.ts → messages.d.ts} +0 -1
- package/dist/types/messages.js +16 -0
- package/dist/types/{types/worker.d.ts → worker.d.ts} +0 -1
- package/dist/types/worker.js +2 -0
- package/dist/worker/bundle-entry.d.ts +1 -0
- package/dist/worker/bundle-entry.js +26 -0
- package/dist/worker/implementation.browser.d.ts +6 -0
- package/dist/worker/implementation.browser.js +24 -0
- package/dist/worker/implementation.d.ts +3 -0
- package/dist/worker/implementation.js +19 -0
- package/dist/worker/implementation.tiny-worker.d.ts +6 -0
- package/dist/worker/implementation.tiny-worker.js +37 -0
- package/dist/worker/implementation.worker_threads.d.ts +8 -0
- package/dist/worker/implementation.worker_threads.js +41 -0
- package/dist/worker/index.d.ts +5 -0
- package/dist/worker/index.js +174 -0
- package/dist/worker_threads.d.ts +8 -0
- package/dist/worker_threads.js +13 -0
- package/eslint.config.mjs +35 -0
- package/index.mjs +10 -0
- package/observable.d.ts +2 -0
- package/observable.js +2 -0
- package/observable.mjs +4 -0
- package/package.json +93 -53
- package/register.d.ts +2 -0
- package/register.js +2 -0
- package/register.mjs +1 -0
- package/rollup.config.js +16 -0
- package/src/common.ts +19 -0
- package/src/index.ts +10 -0
- package/src/master/get-bundle-url.browser.ts +31 -0
- package/src/master/implementation.browser.ts +82 -0
- package/src/master/implementation.node.ts +285 -0
- package/src/master/implementation.ts +21 -0
- package/src/master/index.ts +19 -0
- package/src/master/invocation-proxy.ts +151 -0
- package/src/master/pool-types.ts +83 -0
- package/src/master/pool.ts +399 -0
- package/src/master/register.ts +10 -0
- package/src/master/spawn.ts +172 -0
- package/src/master/thread.ts +29 -0
- package/src/observable-promise.ts +183 -0
- package/src/observable.ts +44 -0
- package/src/ponyfills.ts +31 -0
- package/src/promise.ts +26 -0
- package/src/serializers.ts +68 -0
- package/src/symbols.ts +5 -0
- package/{dist/types/transferable.d.ts → src/transferable.ts} +33 -8
- package/src/types/master.ts +132 -0
- package/src/types/messages.ts +72 -0
- package/src/types/worker.ts +14 -0
- package/src/worker/bundle-entry.ts +10 -0
- package/src/worker/implementation.browser.ts +40 -0
- package/src/worker/implementation.tiny-worker.ts +55 -0
- package/src/worker/implementation.ts +23 -0
- package/src/worker/implementation.worker_threads.ts +50 -0
- package/src/worker/index.ts +230 -0
- package/src/worker_threads.ts +27 -0
- package/test/lib/index.ts +1 -0
- package/test/lib/serialization.ts +38 -0
- package/test/observable-promise.test.ts +205 -0
- package/test/observable.test.ts +87 -0
- package/test/pool.test.ts +183 -0
- package/test/serialization.test.ts +23 -0
- package/test/spawn.chromium.mocha.ts +53 -0
- package/test/spawn.test.ts +87 -0
- package/test/streaming.test.ts +29 -0
- package/test/transferables.test.ts +71 -0
- package/test/workers/arraybuffer-xor.ts +10 -0
- package/test/workers/count-to-five.ts +12 -0
- package/test/workers/counter.ts +19 -0
- package/test/workers/faulty-function.ts +5 -0
- package/test/workers/hello-world.ts +5 -0
- package/test/workers/increment.ts +8 -0
- package/test/workers/minmax.ts +25 -0
- package/test/workers/serialization.ts +13 -0
- package/test/workers/top-level-throw.ts +1 -0
- package/test-tooling/rollup/app.js +21 -0
- package/test-tooling/rollup/rollup.config.ts +14 -0
- package/test-tooling/rollup/worker.js +7 -0
- package/test-tooling/tsconfig/minimal.ts +12 -0
- package/test-tooling/webpack/addition-worker.ts +9 -0
- package/test-tooling/webpack/app-with-inlined-worker.ts +28 -0
- package/test-tooling/webpack/app.ts +61 -0
- package/test-tooling/webpack/pool-worker.ts +5 -0
- package/test-tooling/webpack/raw-loader.d.ts +4 -0
- package/test-tooling/webpack/webpack.chromium.mocha.ts +21 -0
- package/test-tooling/webpack/webpack.node.config.js +29 -0
- package/test-tooling/webpack/webpack.web.config.js +28 -0
- package/types/is-observable.d.ts +7 -0
- package/types/tiny-worker.d.ts +4 -0
- package/types/webworker.d.ts +9 -0
- package/worker.d.ts +2 -0
- package/worker.js +2 -0
- package/worker.mjs +6 -0
- package/dist/browser/master/implementation.browser.mjs +0 -89
- package/dist/browser/master/implementation.browser.mjs.map +0 -1
- package/dist/browser/worker/worker.browser.mjs +0 -291
- package/dist/browser/worker/worker.browser.mjs.map +0 -1
- package/dist/neutral/index.mjs +0 -1022
- package/dist/neutral/index.mjs.map +0 -1
- package/dist/neutral/master/implementation.mjs +0 -264
- package/dist/neutral/master/implementation.mjs.map +0 -1
- package/dist/neutral/master/index.mjs +0 -988
- package/dist/neutral/master/index.mjs.map +0 -1
- package/dist/neutral/master/pool.mjs +0 -579
- package/dist/neutral/master/pool.mjs.map +0 -1
- package/dist/neutral/master/register.mjs +0 -272
- package/dist/neutral/master/register.mjs.map +0 -1
- package/dist/neutral/master/spawn.mjs +0 -412
- package/dist/neutral/master/spawn.mjs.map +0 -1
- package/dist/neutral/master/thread.mjs +0 -29
- package/dist/neutral/master/thread.mjs.map +0 -1
- package/dist/neutral/observable-promise.mjs +0 -132
- package/dist/neutral/observable-promise.mjs.map +0 -1
- package/dist/neutral/observable.mjs +0 -31
- package/dist/neutral/observable.mjs.map +0 -1
- package/dist/node/master/implementation.node.mjs +0 -154
- package/dist/node/master/implementation.node.mjs.map +0 -1
- package/dist/node/worker/worker.node.mjs +0 -304
- package/dist/node/worker/worker.node.mjs.map +0 -1
- package/dist/types/common.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -9
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/master/get-bundle-url.browser.d.ts.map +0 -1
- package/dist/types/master/implementation.browser.d.ts.map +0 -1
- package/dist/types/master/implementation.d.ts.map +0 -1
- package/dist/types/master/implementation.node.d.ts.map +0 -1
- package/dist/types/master/index.d.ts +0 -13
- package/dist/types/master/index.d.ts.map +0 -1
- package/dist/types/master/invocation-proxy.d.ts.map +0 -1
- package/dist/types/master/pool-types.d.ts.map +0 -1
- package/dist/types/master/pool.d.ts +0 -93
- package/dist/types/master/pool.d.ts.map +0 -1
- package/dist/types/master/register.d.ts +0 -2
- package/dist/types/master/register.d.ts.map +0 -1
- package/dist/types/master/spawn.d.ts.map +0 -1
- package/dist/types/master/thread.d.ts +0 -13
- package/dist/types/master/thread.d.ts.map +0 -1
- package/dist/types/observable-promise.d.ts.map +0 -1
- package/dist/types/observable.d.ts +0 -21
- package/dist/types/observable.d.ts.map +0 -1
- package/dist/types/ponyfills.d.ts.map +0 -1
- package/dist/types/promise.d.ts +0 -6
- package/dist/types/promise.d.ts.map +0 -1
- package/dist/types/serializers.d.ts.map +0 -1
- package/dist/types/symbols.d.ts.map +0 -1
- package/dist/types/transferable.d.ts.map +0 -1
- package/dist/types/types/master.d.ts.map +0 -1
- package/dist/types/types/messages.d.ts.map +0 -1
- package/dist/types/types/worker.d.ts.map +0 -1
- package/dist/types/worker/WorkerGlobalScope.d.ts +0 -6
- package/dist/types/worker/WorkerGlobalScope.d.ts.map +0 -1
- package/dist/types/worker/expose.d.ts +0 -4
- package/dist/types/worker/expose.d.ts.map +0 -1
- package/dist/types/worker/worker.browser.d.ts +0 -14
- package/dist/types/worker/worker.browser.d.ts.map +0 -1
- package/dist/types/worker/worker.node.d.ts +0 -25
- package/dist/types/worker/worker.node.d.ts.map +0 -1
package/index.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as Threads from './dist/index.js'
|
|
2
|
+
|
|
3
|
+
export const registerSerializer = Threads.registerSerializer
|
|
4
|
+
export const spawn = Threads.spawn
|
|
5
|
+
export const BlobWorker = Threads.BlobWorker
|
|
6
|
+
export const DefaultSerializer = Threads.DefaultSerializer
|
|
7
|
+
export const Pool = Threads.Pool
|
|
8
|
+
export const Thread = Threads.Thread
|
|
9
|
+
export const Transfer = Threads.Transfer
|
|
10
|
+
export const Worker = Threads.Worker
|
package/observable.d.ts
ADDED
package/observable.js
ADDED
package/observable.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/threads",
|
|
3
|
-
"version": "4.7.
|
|
3
|
+
"version": "4.7.1",
|
|
4
4
|
"description": "Web workers & worker threads as simple as a function call",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"thread",
|
|
@@ -29,88 +29,128 @@
|
|
|
29
29
|
"./register.*js",
|
|
30
30
|
"./worker.*js"
|
|
31
31
|
],
|
|
32
|
-
"type": "module",
|
|
33
32
|
"exports": {
|
|
34
33
|
".": {
|
|
35
|
-
"types": "./dist/
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"browser": {
|
|
40
|
-
"types": "./dist/types/master/implementation.browser.d.ts",
|
|
41
|
-
"import": "./dist/browser/master/implementation.browser.mjs"
|
|
42
|
-
},
|
|
43
|
-
"node": {
|
|
44
|
-
"types": "./dist/types/master/implementation.node.d.ts",
|
|
45
|
-
"import": "./dist/node/master/implementation.node.mjs"
|
|
46
|
-
},
|
|
47
|
-
"types": "./dist/types/master/implementation.d.ts",
|
|
48
|
-
"import": "./dist/neutral/master/implementation.mjs"
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"require": "./dist/index.js",
|
|
36
|
+
"import": "./dist/esm/index.js",
|
|
37
|
+
"default": "./dist/esm/index.js"
|
|
49
38
|
},
|
|
50
39
|
"./master": {
|
|
51
|
-
"types": "./dist/types/master
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"types": "./dist/types/master/spawn.d.ts",
|
|
56
|
-
"import": "./dist/neutral/master/spawn.mjs"
|
|
57
|
-
},
|
|
58
|
-
"./thread": {
|
|
59
|
-
"types": "./dist/types/master/thread.d.ts",
|
|
60
|
-
"import": "./dist/neutral/master/thread.mjs"
|
|
40
|
+
"types": "./dist/types/master.d.ts",
|
|
41
|
+
"require": "./dist/master.js",
|
|
42
|
+
"import": "./dist/esm/master.js",
|
|
43
|
+
"default": "./dist/esm/master.js"
|
|
61
44
|
},
|
|
62
45
|
"./messenger": {
|
|
63
|
-
"types": "./dist/types/
|
|
46
|
+
"types": "./dist/types/messenger.d.ts"
|
|
64
47
|
},
|
|
65
48
|
"./observable": {
|
|
66
|
-
"types": "./dist/
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"types": "./dist/types/master/pool.d.ts",
|
|
71
|
-
"import": "./dist/neutral/master/pool.mjs"
|
|
72
|
-
},
|
|
73
|
-
"./observable-promise": {
|
|
74
|
-
"types": "./dist/types/observable-promise.d.ts",
|
|
75
|
-
"import": "./dist/neutral/observable-promise.mjs"
|
|
49
|
+
"types": "./dist/observable.d.ts",
|
|
50
|
+
"require": "./dist/observable.js",
|
|
51
|
+
"import": "./dist/esm/observable.js",
|
|
52
|
+
"default": "./dist/esm/observable.js"
|
|
76
53
|
},
|
|
77
54
|
"./register": {
|
|
78
|
-
"types": "./dist/
|
|
79
|
-
"
|
|
55
|
+
"types": "./dist/master/register.d.ts",
|
|
56
|
+
"require": "./dist/master/register/index.js",
|
|
57
|
+
"import": "./dist/esm/master/register/index.js",
|
|
58
|
+
"default": "./dist/esm/master/register/index.js"
|
|
80
59
|
},
|
|
81
60
|
"./worker": {
|
|
82
|
-
"
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
"node": {
|
|
87
|
-
"types": "./dist/types/worker/worker.node.d.ts",
|
|
88
|
-
"import": "./dist/node/worker/worker.node.mjs"
|
|
89
|
-
}
|
|
61
|
+
"types": "./dist/types/worker.d.ts",
|
|
62
|
+
"require": "./dist/worker/index.js",
|
|
63
|
+
"import": "./dist/esm/worker/index.js",
|
|
64
|
+
"default": "./dist/esm/worker/index.js"
|
|
90
65
|
}
|
|
91
66
|
},
|
|
92
|
-
"
|
|
93
|
-
"
|
|
67
|
+
"main": "dist/index.js",
|
|
68
|
+
"module": "dist/esm/index.js",
|
|
69
|
+
"browser": {
|
|
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",
|
|
94
87
|
"files": [
|
|
95
|
-
"dist"
|
|
88
|
+
"dist/**",
|
|
89
|
+
"*.js",
|
|
90
|
+
"*.mjs",
|
|
91
|
+
"*.ts"
|
|
96
92
|
],
|
|
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
|
+
"ava": {
|
|
112
|
+
"extensions": [
|
|
113
|
+
"ts"
|
|
114
|
+
],
|
|
115
|
+
"files": [
|
|
116
|
+
"./test/**/*.test.ts",
|
|
117
|
+
"./test-tooling/**/*.test.ts"
|
|
118
|
+
],
|
|
119
|
+
"require": [
|
|
120
|
+
"ts-node/register"
|
|
121
|
+
],
|
|
122
|
+
"serial": true
|
|
123
|
+
},
|
|
97
124
|
"dependencies": {
|
|
125
|
+
"callsites-3-1-0": "npm:callsites@3.1.0",
|
|
98
126
|
"debug": "^4.4.0",
|
|
99
127
|
"is-observable-2-1-0": "npm:is-observable@2.1.0",
|
|
100
128
|
"observable-fns": "^0.6.1"
|
|
101
129
|
},
|
|
102
130
|
"devDependencies": {
|
|
131
|
+
"@babel/types": "^7.26.10",
|
|
132
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
133
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
103
134
|
"@types/debug": "^4.1.12",
|
|
104
135
|
"@types/node": "^22.13.10",
|
|
105
136
|
"@xylabs/eslint-config-flat": "^6.1.3",
|
|
106
137
|
"@xylabs/ts-scripts-yarn3": "^6.1.3",
|
|
107
|
-
"
|
|
138
|
+
"cross-env": "^7.0.3",
|
|
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"
|
|
108
149
|
},
|
|
109
150
|
"optionalDependencies": {
|
|
110
151
|
"tiny-worker": "^2.3.0"
|
|
111
152
|
},
|
|
112
153
|
"publishConfig": {
|
|
113
154
|
"access": "public"
|
|
114
|
-
}
|
|
115
|
-
"stableVersion": "4.6.4"
|
|
155
|
+
}
|
|
116
156
|
}
|
package/register.d.ts
ADDED
package/register.js
ADDED
package/register.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './dist/master/register.js'
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
2
|
+
const commonjs = require('@rollup/plugin-commonjs')
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
4
|
+
const { nodeResolve } = require('@rollup/plugin-node-resolve')
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
plugins: [
|
|
8
|
+
nodeResolve({
|
|
9
|
+
browser: true,
|
|
10
|
+
mainFields: ['module', 'main'],
|
|
11
|
+
preferBuiltins: true,
|
|
12
|
+
}),
|
|
13
|
+
|
|
14
|
+
commonjs(),
|
|
15
|
+
],
|
|
16
|
+
}
|
package/src/common.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import type {
|
|
3
|
+
JsonSerializable, Serializer, SerializerImplementation,
|
|
4
|
+
} from './serializers'
|
|
5
|
+
import { DefaultSerializer, extendSerializer } from './serializers'
|
|
6
|
+
|
|
7
|
+
let registeredSerializer: Serializer<JsonSerializable> = DefaultSerializer
|
|
8
|
+
|
|
9
|
+
export function registerSerializer(serializer: SerializerImplementation<JsonSerializable>) {
|
|
10
|
+
registeredSerializer = extendSerializer(registeredSerializer, serializer)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function deserialize(message: JsonSerializable): any {
|
|
14
|
+
return registeredSerializer.deserialize(message)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function serialize(input: any): JsonSerializable {
|
|
18
|
+
return registeredSerializer.serialize(input)
|
|
19
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
DefaultSerializer, JsonSerializable, Serializer, SerializerImplementation,
|
|
8
|
+
} from './serializers'
|
|
9
|
+
export { Transfer, TransferDescriptor } from './transferable'
|
|
10
|
+
export { expose } from './worker/index'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Source: <https://github.com/parcel-bundler/parcel/blob/master/packages/core/parcel-bundler/src/builtins/bundle-url.js>
|
|
2
|
+
|
|
3
|
+
let bundleURL: string | undefined
|
|
4
|
+
|
|
5
|
+
function getBundleURLCached(): string {
|
|
6
|
+
if (!bundleURL) {
|
|
7
|
+
bundleURL = getBundleURL()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return bundleURL
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getBundleURL(): string {
|
|
14
|
+
// Attempt to find the URL of the current script and use that as the base URL
|
|
15
|
+
try {
|
|
16
|
+
throw new Error('getBundleURL failed')
|
|
17
|
+
} catch (err) {
|
|
18
|
+
const matches = ('' + err.stack).match(/(https?|file|ftp|chrome-extension|moz-extension):\/\/[^\n)]+/g)
|
|
19
|
+
if (matches) {
|
|
20
|
+
return getBaseURL(matches[0])
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return '/'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getBaseURL(url: string): string {
|
|
28
|
+
return ('' + url).replace(/^((?:https?|file|ftp|chrome-extension|moz-extension):\/\/.+)?\/[^/]+(?:\?.*)?$/, '$1') + '/'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { getBundleURLCached as getBundleURL }
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint-disable @stylistic/max-len */
|
|
2
|
+
/* eslint-disable import-x/no-internal-modules */
|
|
3
|
+
// tslint:disable max-classes-per-file
|
|
4
|
+
|
|
5
|
+
import type { ImplementationExport, ThreadsWorkerOptions } from '../types/master'
|
|
6
|
+
import { getBundleURL } from './get-bundle-url.browser'
|
|
7
|
+
|
|
8
|
+
export const defaultPoolSize = typeof navigator !== 'undefined' && navigator.hardwareConcurrency ? navigator.hardwareConcurrency : 4
|
|
9
|
+
|
|
10
|
+
const isAbsoluteURL = (value: string) => /^[A-Za-z][\d+.A-Za-z\-]*:/.test(value)
|
|
11
|
+
|
|
12
|
+
function createSourceBlobURL(code: string): string {
|
|
13
|
+
const blob = new Blob([code], { type: 'application/javascript' })
|
|
14
|
+
return URL.createObjectURL(blob)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function selectWorkerImplementation(): ImplementationExport {
|
|
18
|
+
if (typeof Worker === 'undefined') {
|
|
19
|
+
// Might happen on Safari, for instance
|
|
20
|
+
// The idea is to only fail if the constructor is actually used
|
|
21
|
+
return class NoWebWorker {
|
|
22
|
+
constructor() {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"No web worker implementation available. You might have tried to spawn a worker within a worker in a browser that doesn't support workers in workers.",
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
} as unknown as ImplementationExport
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
class WebWorker extends Worker {
|
|
31
|
+
constructor(url: string | URL, options?: ThreadsWorkerOptions) {
|
|
32
|
+
if (typeof url === 'string' && options && options._baseURL) {
|
|
33
|
+
url = new URL(url, options._baseURL)
|
|
34
|
+
} else if (typeof url === 'string' && !isAbsoluteURL(url) && /^file:\/\//i.test(getBundleURL())) {
|
|
35
|
+
url = new URL(url, getBundleURL().replace(/\/[^/]+$/, '/'))
|
|
36
|
+
if (options?.CORSWorkaround ?? true) {
|
|
37
|
+
url = createSourceBlobURL(`importScripts(${JSON.stringify(url)});`)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (
|
|
41
|
+
typeof url === 'string'
|
|
42
|
+
&& isAbsoluteURL(url) // Create source code blob loading JS file via `importScripts()`
|
|
43
|
+
// to circumvent worker CORS restrictions
|
|
44
|
+
&& (options?.CORSWorkaround ?? true)
|
|
45
|
+
) {
|
|
46
|
+
url = createSourceBlobURL(`importScripts(${JSON.stringify(url)});`)
|
|
47
|
+
}
|
|
48
|
+
super(url, options)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
class BlobWorker extends WebWorker {
|
|
53
|
+
constructor(blob: Blob, options?: ThreadsWorkerOptions) {
|
|
54
|
+
const url = globalThis.URL.createObjectURL(blob)
|
|
55
|
+
super(url, options)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static fromText(source: string, options?: ThreadsWorkerOptions): WebWorker {
|
|
59
|
+
const blob = new globalThis.Blob([source], { type: 'text/javascript' })
|
|
60
|
+
return new BlobWorker(blob, options)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
blob: BlobWorker,
|
|
66
|
+
default: WebWorker,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let implementation: ImplementationExport
|
|
71
|
+
|
|
72
|
+
export function getWorkerImplementation(): ImplementationExport {
|
|
73
|
+
if (!implementation) {
|
|
74
|
+
implementation = selectWorkerImplementation()
|
|
75
|
+
}
|
|
76
|
+
return implementation
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function isWorkerRuntime() {
|
|
80
|
+
const isWindowContext = typeof globalThis !== 'undefined' && typeof Window !== 'undefined' && globalThis instanceof Window
|
|
81
|
+
return typeof globalThis !== 'undefined' && self['postMessage'] && !isWindowContext ? true : false
|
|
82
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
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
|
+
|
|
7
|
+
/* eslint-disable unicorn/prefer-add-event-listener */
|
|
8
|
+
/* eslint-disable unicorn/prefer-event-target */
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
10
|
+
/* eslint-disable unicorn/text-encoding-identifier-case */
|
|
11
|
+
/// <reference lib="dom" />
|
|
12
|
+
|
|
13
|
+
import { EventEmitter } from 'node:events'
|
|
14
|
+
import { cpus } from 'node:os'
|
|
15
|
+
import path from 'node:path'
|
|
16
|
+
import { fileURLToPath } from 'node:url'
|
|
17
|
+
|
|
18
|
+
import type { CallSite } from 'callsites-3-1-0'
|
|
19
|
+
import getCallsites from 'callsites-3-1-0'
|
|
20
|
+
|
|
21
|
+
import type {
|
|
22
|
+
ImplementationExport, ThreadsWorkerOptions, WorkerImplementation,
|
|
23
|
+
} from '../types/master'
|
|
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
|
+
}
|
|
30
|
+
|
|
31
|
+
declare const __non_webpack_require__: typeof require
|
|
32
|
+
declare const self: WorkerGlobalScope
|
|
33
|
+
|
|
34
|
+
type WorkerEventName = 'error' | 'message'
|
|
35
|
+
|
|
36
|
+
let tsNodeAvailable: boolean | undefined
|
|
37
|
+
|
|
38
|
+
export const defaultPoolSize = cpus().length
|
|
39
|
+
|
|
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
|
+
function resolveScriptPath(scriptPath: string, baseURL?: string | undefined) {
|
|
87
|
+
const makeRelative = (filePath: string) => {
|
|
88
|
+
// eval() hack is also webpack-related
|
|
89
|
+
return path.isAbsolute(filePath) ? filePath : path.join(baseURL || eval('__dirname'), filePath)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return typeof __non_webpack_require__ === 'function'
|
|
93
|
+
? __non_webpack_require__.resolve(makeRelative(scriptPath))
|
|
94
|
+
: eval('require').resolve(makeRelative(rebaseScriptPath(scriptPath, /[/\\]worker_threads[/\\]/)))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function initWorkerThreadsWorker(): ImplementationExport {
|
|
98
|
+
// Webpack hack
|
|
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> = []
|
|
103
|
+
|
|
104
|
+
class Worker extends NativeWorker {
|
|
105
|
+
private mappedEventListeners: WeakMap<EventListener, EventListener>
|
|
106
|
+
|
|
107
|
+
constructor(scriptPath: string, options?: ThreadsWorkerOptions & { fromSource: boolean }) {
|
|
108
|
+
const resolvedScriptPath = options && options.fromSource ? null : resolveScriptPath(scriptPath, (options || {})._baseURL)
|
|
109
|
+
|
|
110
|
+
if (!resolvedScriptPath) {
|
|
111
|
+
// `options.fromSource` is true
|
|
112
|
+
const sourceCode = scriptPath
|
|
113
|
+
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
|
+
}
|
|
122
|
+
|
|
123
|
+
this.mappedEventListeners = new WeakMap()
|
|
124
|
+
allWorkers.push(this)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
addEventListener(eventName: string, rawListener: EventListener) {
|
|
128
|
+
const listener = (message: any) => {
|
|
129
|
+
rawListener({ data: message } as any)
|
|
130
|
+
}
|
|
131
|
+
this.mappedEventListeners.set(rawListener, listener)
|
|
132
|
+
this.on(eventName, listener)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
removeEventListener(eventName: string, rawListener: EventListener) {
|
|
136
|
+
const listener = this.mappedEventListeners.get(rawListener) || rawListener
|
|
137
|
+
this.off(eventName, listener)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const terminateWorkersAndMaster = () => {
|
|
142
|
+
// we should terminate all workers and then gracefully shutdown self process
|
|
143
|
+
Promise.all(allWorkers.map(worker => worker.terminate())).then(
|
|
144
|
+
() => process.exit(0),
|
|
145
|
+
() => process.exit(1),
|
|
146
|
+
)
|
|
147
|
+
allWorkers = []
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Take care to not leave orphaned processes behind. See #147.
|
|
151
|
+
process.on('SIGINT', () => terminateWorkersAndMaster())
|
|
152
|
+
process.on('SIGTERM', () => terminateWorkersAndMaster())
|
|
153
|
+
|
|
154
|
+
class BlobWorker extends Worker {
|
|
155
|
+
constructor(blob: Uint8Array, options?: ThreadsWorkerOptions) {
|
|
156
|
+
super(Buffer.from(blob).toString('utf-8'), { ...options, fromSource: true })
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static fromText(source: string, options?: ThreadsWorkerOptions): WorkerImplementation {
|
|
160
|
+
return new Worker(source, { ...options, fromSource: true }) as any
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
blob: BlobWorker as any,
|
|
166
|
+
default: Worker as any,
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function initTinyWorker(): ImplementationExport {
|
|
171
|
+
const TinyWorker = require('tiny-worker')
|
|
172
|
+
|
|
173
|
+
let allWorkers: Array<typeof TinyWorker> = []
|
|
174
|
+
|
|
175
|
+
class Worker extends TinyWorker {
|
|
176
|
+
private emitter: EventEmitter
|
|
177
|
+
|
|
178
|
+
constructor(scriptPath: string, options?: ThreadsWorkerOptions & { fromSource?: boolean }) {
|
|
179
|
+
// Need to apply a work-around for Windows or it will choke upon the absolute path
|
|
180
|
+
// (`Error [ERR_INVALID_PROTOCOL]: Protocol 'c:' not supported`)
|
|
181
|
+
const resolvedScriptPath
|
|
182
|
+
= options && options.fromSource
|
|
183
|
+
? null
|
|
184
|
+
: process.platform === 'win32'
|
|
185
|
+
? `file:///${resolveScriptPath(scriptPath).replaceAll('\\', '/')}`
|
|
186
|
+
: resolveScriptPath(scriptPath)
|
|
187
|
+
|
|
188
|
+
if (!resolvedScriptPath) {
|
|
189
|
+
// `options.fromSource` is true
|
|
190
|
+
const sourceCode = scriptPath
|
|
191
|
+
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
|
+
}
|
|
200
|
+
|
|
201
|
+
allWorkers.push(this)
|
|
202
|
+
|
|
203
|
+
this.emitter = new EventEmitter()
|
|
204
|
+
this.onerror = (error: Error) => this.emitter.emit('error', error)
|
|
205
|
+
this.onmessage = (message: MessageEvent) => this.emitter.emit('message', message)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
addEventListener(eventName: WorkerEventName, listener: EventListener) {
|
|
209
|
+
this.emitter.addListener(eventName, listener)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
removeEventListener(eventName: WorkerEventName, listener: EventListener) {
|
|
213
|
+
this.emitter.removeListener(eventName, listener)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
terminate() {
|
|
217
|
+
allWorkers = allWorkers.filter(worker => worker !== this)
|
|
218
|
+
return super.terminate()
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const terminateWorkersAndMaster = () => {
|
|
223
|
+
// we should terminate all workers and then gracefully shutdown self process
|
|
224
|
+
Promise.all(allWorkers.map(worker => worker.terminate())).then(
|
|
225
|
+
() => process.exit(0),
|
|
226
|
+
() => process.exit(1),
|
|
227
|
+
)
|
|
228
|
+
allWorkers = []
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Take care to not leave orphaned processes behind
|
|
232
|
+
// See <https://github.com/avoidwork/tiny-worker#faq>
|
|
233
|
+
process.on('SIGINT', () => terminateWorkersAndMaster())
|
|
234
|
+
process.on('SIGTERM', () => terminateWorkersAndMaster())
|
|
235
|
+
|
|
236
|
+
class BlobWorker extends Worker {
|
|
237
|
+
constructor(blob: Uint8Array, options?: ThreadsWorkerOptions) {
|
|
238
|
+
super(Buffer.from(blob).toString('utf-8'), { ...options, fromSource: true })
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
static fromText(source: string, options?: ThreadsWorkerOptions): WorkerImplementation {
|
|
242
|
+
return new Worker(source, { ...options, fromSource: true }) as any
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
blob: BlobWorker as any,
|
|
248
|
+
default: Worker as any,
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
let implementation: ImplementationExport
|
|
253
|
+
let isTinyWorker: boolean
|
|
254
|
+
|
|
255
|
+
function selectWorkerImplementation(): ImplementationExport {
|
|
256
|
+
try {
|
|
257
|
+
isTinyWorker = false
|
|
258
|
+
return initWorkerThreadsWorker()
|
|
259
|
+
} catch {
|
|
260
|
+
// tslint:disable-next-line no-console
|
|
261
|
+
console.debug('Node worker_threads not available. Trying to fall back to tiny-worker polyfill...')
|
|
262
|
+
isTinyWorker = true
|
|
263
|
+
return initTinyWorker()
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function getWorkerImplementation(): ImplementationExport {
|
|
268
|
+
if (!implementation) {
|
|
269
|
+
implementation = selectWorkerImplementation()
|
|
270
|
+
}
|
|
271
|
+
return implementation
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function isWorkerRuntime() {
|
|
275
|
+
if (isTinyWorker) {
|
|
276
|
+
return self !== undefined && self['postMessage'] ? true : false
|
|
277
|
+
} else {
|
|
278
|
+
// Webpack hack
|
|
279
|
+
const isMainThread
|
|
280
|
+
= typeof __non_webpack_require__ === 'function'
|
|
281
|
+
? __non_webpack_require__('worker_threads').isMainThread
|
|
282
|
+
: eval('require')('worker_threads').isMainThread
|
|
283
|
+
return !isMainThread
|
|
284
|
+
}
|
|
285
|
+
}
|