2 ms·
web workers requires a separate source file, and makes you sweat the details of the structured clone algorithm. It feels absurd coming from other languages: so
by ridiculous_fish 5y ago
web workers requires a separate source file, and makes you sweat the details of the structured clone algorithm. It feels absurd coming from other languages: so much ceremony!
There is parallel.js, which allows you to just pass your task as a function:
p.spawn(someFunc, someArg)
This is nice to use, but the implementation is forced to serialize the function via toString, and then eval it in the thread. This prevents the function from capturing anything or calling other functions, which are serious limitations.
It's unfortunate that there's no way to to just "run this function in the background" like so many other languages has. Filip Pizlo explored what it would take: https://webkit.org/blog/7846/concurrent-javascript-it-can-work/ https://webkit.org/blog/7846/concurrent-javascript-it-can-wo... , it's technically doable at least for JSC but is unlikely to ever happen.
Anyways background computation is one of the weakest parts of JavaScript. Happily wasm threads don't have the same limitations and so can take over.