From 79c58502c7a9a0a76ab1081a310b1179a852d16f Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Sat, 21 Dec 2024 23:43:02 +0000 Subject: [PATCH] Only assert under debug mode --- src/lib.rs | 4 ++++ src/workerHelpers.js | 4 ---- src/workerHelpers.no-bundler.js | 4 ---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a96ca67..373caa5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,6 +55,10 @@ extern "C" { #[wasm_bindgen] impl wbg_rayon_PoolBuilder { fn new(num_threads: usize) -> Self { + #[cfg(debug_assertions)] + if num_threads == 0 { + wasm_bindgen::throw_str("Number of threads must be greater than zero."); + } let (sender, receiver) = bounded(num_threads); Self { num_threads, diff --git a/src/workerHelpers.js b/src/workerHelpers.js index 68a3ec8..c681506 100644 --- a/src/workerHelpers.js +++ b/src/workerHelpers.js @@ -53,10 +53,6 @@ waitForMsgType(self, 'wasm_bindgen_worker_init').then(async data => { }); export async function startWorkers(module, memory, builder) { - if (builder.numThreads() === 0) { - throw new Error(`num_threads must be > 0.`); - } - const workerInit = { type: 'wasm_bindgen_worker_init', init: { module, memory }, diff --git a/src/workerHelpers.no-bundler.js b/src/workerHelpers.no-bundler.js index 231e5c5..91356e7 100644 --- a/src/workerHelpers.no-bundler.js +++ b/src/workerHelpers.no-bundler.js @@ -35,10 +35,6 @@ waitForMsgType(self, 'wasm_bindgen_worker_init').then(async data => { }); export async function startWorkers(module, memory, builder) { - if (builder.numThreads() === 0) { - throw new Error(`num_threads must be > 0.`); - } - const workerInit = { type: 'wasm_bindgen_worker_init', init: { module, memory },