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 BethGriggs committed May 10, 2019
1 parent a9b6aea commit 522d8eb
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 522d8eb

Please sign in to comment.