mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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:
1 parent
4e2ceba908
commit
fcc03c1d44
1 file changed
+3
-4
@@ -40,12 +40,11 @@ const noop = () => {};
|
||||
const hasCrypto = Boolean(process.versions.openssl);
|
||||
|
||||
const isMainThread = (() => {
|
||||
try {
|
||||
if (require('module').builtinModules.includes('worker_threads')) {
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user