26 ms·
The problem is mostly in that all these functions are closures, and scope can’t easily be transferred. Domenic and I have been working on a proposal[1] called
by dassurma 7y ago
The problem is mostly in that all these functions are closures, and scope can’t easily be transferred.
Domenic and I have been working on a proposal[1] called Blöcks to introduce transferable functions to JavaScript.
In the meantime, I wrote Clooney[2] ontop of Comlink[3] that gives you almost that.
[1]: https://github.com/domenic/proposal-blocks https://github.com/domenic/proposal-blocks
[2]: https://github.com/GoogleChromeLabs/clooney https://github.com/GoogleChromeLabs/clooney
[3]: https://github.com/GoogleChromeLabs/comlink https://github.com/GoogleChromeLabs/comlink
- ajkjk 7y agoOo, I'm really interested that you're working on that, although I don't love the syntax (particularly `worker<endpoint>` seems awkward). It seems like you should stick with function invocation syntax: `worker = (endpoint) => {| block |}` `worker(endpont) // does what you want` with the difference that the result isn't a closure. As a bonus this syntax would let you write 'pure functions' even if you weren't working with workers. Perhaps the worker version then is `worker = async (endpoint => {| block... |}`. Although considering the precedence for `async function` maybe the way to do this ought to be `pure function`.
- dassurma 7y agoIf you take a look at the issues on the repo, a lot of people agree with you. The syntax was not final at all, we need to convince TC39 first before we can start bikeshedding ^^
- dbetteridge 7y agoWeb workers would make a good http203 episode, uses/pitfalls etc