From 522d8ebc18e5e301bb97ed44e24048d29fd25f11 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 28 Dec 2018 08:55:38 -0800 Subject: [PATCH] test: remove try/catch in common.isMainThread Refactor common.isMainThread. PR-URL: https://github.com/nodejs/node/pull/25249 Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater Reviewed-By: Luigi Pinca --- test/common/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/common/index.js b/test/common/index.js index b4e6f463de6e98..107721d25ed2f7 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -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