Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Support for web workers #641
The only example I can find for using a web worker with WebSharper is this old demo:
Having explicit support for targeting a web worker from WebSharper would be useful. What I'm currently trialing in WebSharper 4.x/Zafir is:
Configure projects as libraries
(previously this was
that outputs everything into \Content\Scripts\WebSharper
You can then manually determine the libaries you need and import them (and bundle as desired):
Hope this helps, having something like this route documented would be really useful! In WebSharper 3.x this was a bit easier as you can get everything in concatenated form.
To add some background on this, it seems potentially very useful to have direct support for web workers with build templates. This would let us progressive add our F# based modules to larger web based tools – ones where we currently call onto the server for those parts. There would also the be the possibility to optimise those modules as the functions we actually call don’t touch much of the BCL.
Unfortunately, this seems to have gotten more awkward, possibly with recent versions (using Zafir.220.127.116.11-beta6) as the generated code directly looks for Global on
eval("self.window = self"); // Load the transcompiled F# code. importScripts("websharperlibs.js"); importScripts("ourtranspiledlib.js"); eval("delete self.window");
note: I used eval as TypeScript sensibly marks self as read-only so this may not work indefinitely but you might also be able to do without that.
It would be great if WebSharper could look for its global on
Any news on this one? It would be great to have direct, clean support for Web Workers.
In case it's useful, as an update I needed to use this in a context where eval was prohibited. I found a better approach in TypeScript of just casting away read-only (and rest of type):
let selfLocal: any = self; selfLocal.window = self; // Load the transcompiled F# code. importScripts("websharperlibs.js"); importScripts("ourtranspiledlib.js"); delete selfLocal.window;