test: remove try/catch in common.isMainThread
Refactor common.isMainThread. PR-URL: https://github.com/nodejs/node/pull/25249 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
39a2ac4c6b
commit
9c2b14013b
@ -39,12 +39,11 @@ const noop = () => {};
|
|||||||
const hasCrypto = Boolean(process.versions.openssl);
|
const hasCrypto = Boolean(process.versions.openssl);
|
||||||
|
|
||||||
const isMainThread = (() => {
|
const isMainThread = (() => {
|
||||||
try {
|
if (require('module').builtinModules.includes('worker_threads')) {
|
||||||
return require('worker_threads').isMainThread;
|
return require('worker_threads').isMainThread;
|
||||||
} catch {
|
|
||||||
// Worker module not enabled → only a single main thread exists.
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
// Worker module not enabled → only a single main thread exists.
|
||||||
|
return true;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Check for flags. Skip this for workers (both, the `cluster` module and
|
// Check for flags. Skip this for workers (both, the `cluster` module and
|
||||||
|
Loading…
x
Reference in New Issue
Block a user