我正在尝试在node.js
.
const { Worker, isMainThread, parentPort } = require('worker_threads');
if (isMainThread) {
// This code is executed in the main thread and not in the worker.
// Create the worker.
const worker = new Worker(__filename);
// Listen for messages from the worker and print them.
worker.on('message', (msg) => { console.log(msg); });
} else {
// This code is executed in the worker and not in the main thread.
// Send a message to the main thread.
parentPort.postMessage('Hello world!');
}
我保存上面的代码并在终端上index.js
运行。node --experimental-worker index.js
我收到以下错误:
节点:错误选项:--experimental-worker。
我v8.16.0
的 Mac 中安装了节点。