javascript - 将 node.js 工作线程与 Meteor 应用程序一起使用
问题描述
我正在尝试在我的 Meteor 应用程序中使用工作线程来卸载 CPU 密集型任务。我直接使用 @arrows/worker 库而不是 worker_threads 模块。我尝试了一些非常简单的测试代码(如下),但出现以下错误。
events.js:288
throw er; // Unhandled 'error' event
^
ReferenceError: meteorInstall is not defined
at Object.<anonymous> (meteor://app/app/app.js:1:15)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at MessagePort.<anonymous> (internal/main/worker_thread.js:162:24)
at MessagePort.emit (events.js:311:20)
at MessagePort.onmessage (internal/worker/io.js:78:8)
Emitted 'error' event on Worker instance at:
at Worker.[kOnErrorMessage] (internal/worker.js:204:10)
at Worker.[kOnMessage] (internal/worker.js:214:37)
at MessagePort.<anonymous> (internal/worker.js:141:57)
at MessagePort.emit (events.js:311:20)
at MessagePort.EventEmitter.emit (domain.js:482:12)
at MessagePort.onmessage (internal/worker/io.js:78:8)
测试代码:
import worker from '@arrows/worker';
const fn = function (data) {
console.log('fn');
return 'abc';
};
const asyncFn = worker(fn);
const runIt = async () => {
console.log('a');
try {
const out = await asyncFn('a');
console.log('b', out);
}
catch (err) { console.log(err); }
}
runIt();
解决方案
推荐阅读
- r - 使用滑动窗口计算 data.frame 中落在某个范围内的值
- c# - 单击系统托盘图标时如何防止当前窗口失去焦点
- gnuplot - Mojolicious 不加载绝对的 javascript 和 CSS 文件
- java - 是否可以在 ActiveMQ/JMS 的 Spring 注释中使用局部变量?
- javascript - 如何在 HTML 画布中获取正确的鼠标坐标
- python - 使用 Python 使我的逻辑回归测试准确度更接近我的训练准确度
- python - 如何多处理 Api 发布请求
- c# - 避免重复插入数据库
- swift - NSPopover 打开后没有收到第一次点击
- sqlalchemy - Sqlalchemy-Marshmallow - 嵌套字段不显示任何数据