gloo icon indicating copy to clipboard operation
gloo copied to clipboard

Complete gloo-worker webassembly example running in a browser

Open jin-eld opened this issue 2 years ago • 2 comments

Hi,

I don't know if I was missing the obvious, but from the documentation and examples alone I was not immediately able to figure out how to actually put all the bits and pieces together in order to get a working setup of a main application that is being loaded via index.html and which then spawns a worker via Rust and communicates with it.

The part that kept confusing me most was, that for instance in the prime example the worker code seemed to reside in the same source file as the function that spawns it and it took me a while to figure out, that the function marked as #[reactor] apparently needs to be shared between both the code that does the spawning and the code that is representing the worker.

Further, I was and actually still am totally confused about the interaction of the buttons in the prime example html and the Rust code, my targeted use case was anyway much simpler. In the end I was able to get something working that provided the setup that I needed: https://github.com/jin-eld/gloo-worker-example

Can't say if I implemented everything in a way it was meant to be used from the gloo API perspective, I am also new to Rust, but it works; comments on that are welcome. Please let me know f you are interested in the above example, if yes, then I'd be willing to implement it in a pull request, otherwise I'll just leave the repo around in case someone else has a hard time to get started.

jin-eld avatar Jan 22 '24 17:01 jin-eld

Using @jin-eld example is the only way I have found to make the gloo worker work. However, it's really different from the simple example found in the documentation, for instance here:

https://docs.rs/gloo-worker/latest/gloo_worker/oneshot/index.html

Am I doing something wrong?

faxioman avatar Feb 28 '24 07:02 faxioman

The gloo examples are to be used with trunk, which is the defacto build tool for rust/wasm frontend frameworks. The index.html is read by trunk. I think we should clarify that, perhaps even add a readme for examples.

Would you mind creating such a PR?

ranile avatar Feb 28 '24 12:02 ranile