节点:错误的选择:
我正在尝试在node.js
中使用worker_threads。
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。
我的Mac中已安装v8.16.0
节点。
Worker
类已在nodejs v10.5.0中添加。
要使用Worker
,至少需要nodejs v10.5.0
具有--experimental-worker
,它很稳定,可以在没有nodejs v12.x的情况下使用
下载:--experimental-worker
版本管理器:nodejs
节点:错误的选择:
我正在尝试在node.js
中使用worker_threads。
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。
我的Mac中已安装v8.16.0
节点。
Worker
类已在nodejs v10.5.0中添加。
要使用Worker
,至少需要nodejs v10.5.0
具有--experimental-worker
,它很稳定,可以在没有nodejs v12.x的情况下使用
下载:--experimental-worker
版本管理器:nodejs