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:
Rich Trott authored and Myles Borins committed 2019-05-16 14:56:14 -04:00
1 parent 4e2ceba908
commit fcc03c1d44
1 file changed
+3 -4
+3 -4
View File
@@ -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