worker.isMainThread


新增于: v10.5.0

如果此代码不在 Worker 线程内运行,则为 true

\Is true if this code is not running inside of a Worker thread.

const { Worker, isMainThread } = require('node:worker_threads');
if (isMainThread) {
 // This re-loads the current file inside a Worker instance.
 new Worker(__filename);
} else {
 console.log('Inside Worker!');
 console.log(isMainThread); // Prints 'false'.
} 

AltStyle によって変換されたページ (->オリジナル) /