UNPKG

process-worker-executor

Version:

将多进程和多线程封装为统一的 Async/Await 调用方式, 简化 IPC 消息通信的复杂性

15 lines (11 loc) 361 B
const ExecutorClient = require('../ExecutorClient') const { parentPort } = require('worker_threads') class WorkerExecutorClient extends ExecutorClient { onInit() { parentPort.on('message', (...args) => this.on(...args)) } async onSend(msg) { parentPort.postMessage(msg) } } module.exports = WorkerExecutorClient