Skip to content

Commit

Permalink
test: remove try/catch in common.isMainThread
Browse files Browse the repository at this point in the history
Refactor common.isMainThread.

PR-URL: #25249
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
Trott authored and MylesBorins committed May 16, 2019
1 parent 4e2ceba commit fcc03c1
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fcc03c1

Please sign in to comment.