Skip to content

Commit b98ccbf

Browse files
authored
Merge pull request #35 from GoogleChromeLabs/node-workers
Add support for node worker threads
2 parents 8cda3c6 + 5877efb commit b98ccbf

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A small library to detect which features of WebAssembly are supported.
66
- ✅ Runs in Node
77
- ✅ Provided as an ES6 module, CommonJS and UMD module.
88
- ✅ CSP compatible
9-
- ✅ Only ~520B gzipped
9+
- ✅ Only ~570B gzipped
1010

1111
## Installation
1212

rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default ["esm", "cjs", "umd"].map(format => ({
2626
preferConst: true,
2727
esModule: false
2828
},
29+
external: ["worker_threads"],
2930
plugins: [
3031
indexGenerator({
3132
indexPath: "./src/index.js",

src/detectors/threads/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313

1414
export default async moduleBytes => {
1515
try {
16+
const MessageChannelConstructor =
17+
typeof MessageChannel !== "undefined"
18+
? MessageChannel
19+
: await import("worker_threads").then(m => m.MessageChannel);
1620
// Test for transferability of SABs (needed for Firefox)
1721
// https://groups.google.com/forum/#!msg/mozilla.dev.platform/IHkBZlHETpA/dwsMNchWEQAJ
18-
new MessageChannel().port1.postMessage(new SharedArrayBuffer(1));
22+
new MessageChannelConstructor().port1.postMessage(new SharedArrayBuffer(1));
1923
return WebAssembly.validate(moduleBytes);
2024
} catch (e) {
2125
return false;

0 commit comments

Comments
 (0)