node工作线程
发表于|更新于
|字数总计:130|阅读时长:1分钟
https://nodejs.org/api/worker_threads.html#worker-threads
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| const { Worker, isMainThread, parentPort } = require('node:worker_threads'); if (isMainThread) { const worker = new Worker(__filename); worker.once('message', (message) => { console.log(message); }); worker.postMessage('Hello, world!'); } else { parentPort.once('message', (message) => { parentPort.postMessage(message); }); }
const { Worker, isMainThread, workerData } = require('node:worker_threads'); if (isMainThread) { const worker = new Worker(__filename, { workerData: 'Hello, world!' }); } else { console.log(workerData); }
|
once -> waitFor block
WebAssembly线程
https://blog.csdn.net/qq_34754747/article/details/105096008