一只萌萌小番薯
有关如何在 node js 中进行多线程的帮助。您必须创建以下三个文件索引.mjsimport run from './Worker.mjs';/*** design your input list of zip files here and send them to `run` one file name at a time* to zip, using a loop or something. It acts as promise.* exmaple : run( <your_input> ).then( <your_output> );**/Worker.mjsimport { Worker } from 'worker_threads';function runService(id, options) { return new Promise((resolve, reject) => { const worker = new Worker('./src/WorkerService.mjs', { workerData: { <your_input> } }); worker.on('message', res => resolve({ res: res, threadId: worker.threadId })); worker.on('error', reject); worker.on('exit', code => { if (code !== 0) reject(new Error(`Worker stopped with exit code ${code}`)); }); });}async function run(id, options) { return await runService(id, options);}export default run;WorkerService.mjsimport { workerData } from 'worker_threads';// Here goes your logic for zipping a file, where as `workerData` will have <your_input>.如果有帮助,请告诉我。