You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
imo it would be nice to get also the event system typed. Any plans or ideas for that?
At the moment a possible solution is to use specta to create at least the typescript types automatically. But you can still misspell the event identifiers. I also rly like the idea of the .wit files.
Yeah so the way I plan to bring this to tauri-bindgen is through something completely different: streams.
This is essentially the same as in GRPC if you're familiar with that, if not here's the gist:
On the guest side this would map to AsyncIterator for JS and SomeSpecificStreamType<String> for Rust probably.
So no events in the classical tauri sense (imo superior though bc it forces cleaner code) but I hope it can fulfill all the use cases.
Edit: If you want a similar behavior to events right now under this stream model you'd use an tokio::sync::mpsc channel like so:
structLogData{rx: mpsc::Receiver<String>}implLogforLogData{typeStartLoggingStream = Pin<Box<tokio_stream::wrappers::ReceiverStream<String>>>;fnstart_logging(&self) -> Result<Self::StartLoggingStream>{let rx = todo!();// haven't figured out how to do this yetlet stream = tokio_stream::wrappers::ReceiverStream::new(rx);Ok(Box::pin(stream))}}
And now you can use the mpsc::Sender handles across the codebase like you'd call win.emit() (but with more safety)
Activity
JonasKruckenberg commentedon Sep 10, 2023
Yeah so the way I plan to bring this to
tauri-bindgen
is through something completely different:stream
s.This is essentially the same as in GRPC if you're familiar with that, if not here's the gist:
which would translate to something like this for the host
Similar to how the
tonic
crate handles this.On the guest side this would map to
AsyncIterator
for JS andSomeSpecificStreamType<String>
for Rust probably.So no events in the classical tauri sense (imo superior though bc it forces cleaner code) but I hope it can fulfill all the use cases.
Edit: If you want a similar behavior to events right now under this stream model you'd use an
tokio::sync::mpsc
channel like so:And now you can use the
mpsc::Sender
handles across the codebase like you'd callwin.emit()
(but with more safety)