Closed benjamin-thomas closed 2 years ago
Thanks for opening this. You can bind any instance of a struct to the frontend using the standard bind method. You should probably run your emitter in a goroutine. Listening to the event using EventsOn should then tie it together.
@leaanthony can you give us an example? So far I'm trying to use websocket to achieve the result but it implies to have an http server so if you have another solution that would be great!
@giovapanasiti I intend to implement and point to a little demo in the next few days to talk about a solution or a recommendation to some kind of pattern because all is not clear in my head at the moment :)
Hello,
Could you have a look at this repo ? https://github.com/benjamin-thomas/wails-async-demo2
I tried to play around with the idea of implementing an emitter, but got lost on the way :)
Ideally I think I would want to consume the output of a channel, or something similar to it. But that's not doable.
Is this the only way to have async communication with the backend?
runtime.EventsEmit
and a custom event from the backendThanks
Yes, that's the standard way of doing it. All the comms between frontend and backend is async anyway, as I'm sure you're aware. I did think a JS equivalent of a channel would be cool but I'm not sure what the use case really is right now.
Is your feature request related to a problem? Please describe.
I would like to call a function from the frontend, but without knowing its total execution time. That function could take a few seconds to complete, but I could also have some data available after a few milliseconds.
I would like the UI to react as soon as some data is available for a nicer user experience.
So I've been thinking how to implement a pub/sub pattern, or some kind of emitter from the backend.
Have you thought about this problem at all?
Describe the solution you'd like
From the backend perspective, I would like to write something like:
But I don't see how the frontend would be able to call such a method at the moment?
From the frontend perpective, I would like to write something like:
But I failed to find some code constructs that would allow the 2 to communicate in an async fashion.
Calling
runtime.EventsOn
from the backend and frontend works though but it'd be nice if we could isolate emitted events/messages close to the method call to prevent jQuery style event soup :)Describe alternatives you've considered
I tried to play with the idea of returning a custom type, but its public functions are not available to the frontend so I'm pretty limited.
Additional context
Not a request, but just a vague idea. Unless I'm mistaken, reactive extensions are available in many languages and could provide the common ground for the backend/frontend async operations.
So maybe integrating parts of those libraries could be a nice addition to wails?