最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

节点:错误的选择:

IT培训 admin 10浏览 0评论

节点:错误的选择:

我正在尝试在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

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论