Re:JavaScript in Parallel: Web Workers and SharedArrayBuffer
by gp7 on Friday March 03, 2017 @08:10PM
(#13788484)
You can just call toString on a function and Blob the string. You have to keep your head straight about the fact that scopes won't transfer (no closures), which is probably why the API doesn't do it for you.
Re:JavaScript in Parallel: Web Workers and SharedArrayBuffer
by bartread on Saturday March 04, 2017 @06:47AM
(#13790485)
Yeah, this ticked me off as well because the use of Web Workers feels extremely un-idiomatic, but what you've said makes sense. If you just passed a function it might dupe people into thinking closures would work or, and this is perhaps worse, force the standard down the route of copying all the values available in the current closure into the worker's scope, which just sounds like a terrible idea to me.
Re:JavaScript in Parallel: Web Workers and SharedArrayBuffer
by ridiculous_fish on Friday March 03, 2017 @08:54PM
(#13788654)
This didn't work in my case because I had references to other functions, for complex number handling and the like. I ended up just loading the whole minified .js file again in the Worker, which worked though it felt ridiculous.
Re:JavaScript in Parallel: Web Workers and SharedArrayBuffer
by btbuildem on Saturday March 04, 2017 @12:42AM
(#13789501)
One of the native functions available in a web worker is importScript - it allows to load include other scripts (eg lodash) into the worker scope.
Re:JavaScript in Parallel: Web Workers and SharedArrayBuffer
by vanderZwan on Saturday March 04, 2017 @07:22AM
(#13790584)
I wonder if bundlers like WebPack could make life simpler here..
I expected to instantiate a WebWorker with a function, and was surprised to discover you have to give it a separate JavaScript file. It is not easy to adopt.