Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds the initial implementation of streaming responses of functions aka the
stream
pseudo-type.It's a pseudo to type because while it looks like any regular type:
stream<t>
the only valid position where it may appear is as the sole return type of a function like so(This restriction might be gradually lifted at some point)
The primary motivation for this new addition is to model sequences of asynchronously produced data such as events, log streams, or just streaming bytes from e.g. the disk.
With this addition the
tauri-bindgen
system can finally replace the current IPC system as this allows us to model events (in an IMO type-safer and more ergonomically way)Details
The generated guest rust code look like this:
where
::tauri_bindgen_guest_rust::Streaming<T>
takes care of the underlying raw http stream and deserialisation of the incoming data. It in turn implementsStream<Item = T>
.It's worth noting that currently the implementation relies on
ReadableStreams
returned byfetch
, and so performs no additional buffering (everything follows the rust pull-based model here which is nice).Streaming<T>
doesn't implement framing yet though it probably should.The generated host code looks like this:
So an implementation would need to give a specific type for
StreamingBytesStream
(most likely some wrapper type)The above example also showcases how a similar DX to the classical tauri events can be achieved, by essentially passing around
mpsc::Sender
handles.TODO list
This closes #180