GoogleChromeLabs / wasm-bindgen-rayon

An adapter for enabling Rayon-based concurrency on the Web with WebAssembly.
https://github.com/RReverser/wasm-bindgen-rayon
Apache License 2.0
404 stars 35 forks source link

Throw an error when number of threads is 0 #21

Closed zxch3n closed 2 years ago

zxch3n commented 2 years ago

Related issue: #20

RReverser commented 2 years ago

Actually, given that this is purely invoking JS APIs, let's move this check to startWorkers in https://github.com/GoogleChromeLabs/wasm-bindgen-rayon/blob/main/src/workerHelpers.js and https://github.com/GoogleChromeLabs/wasm-bindgen-rayon/blob/main/src/workerHelpers.no-bundler.js instead.

That will be a bit cheaper, because it won't require few extra roundtrips to JS, and, correspondingly, will also produce slightly smaller output.

zxch3n commented 2 years ago

Done. And make it throw if one uses a negative thread number.

RReverser commented 2 years ago

I'd prefer to keep things as simple as possible.

I can see why someone might make a mistake of passing 0, but passing a negative number seems less likely. Can you please revert to the same check & message you had in Rust code, but move it to JS?

zxch3n commented 2 years ago

done

RReverser commented 2 years ago

Thanks!