-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
With the current implementation, the documented way to use the stream in the examples is
while let Ok(event) = event_stream.next().await {
...
}
This means if an error is hit, such as a parsing failure (which I have encountered), then:
- You don't know what error has been hit, It could be a parsing failure, in which case it's fine, but it could be the websocket is closed.
- You need to
loopover thewhileloop in order to keep using the connection if an error is hit. - If you do access the error, you should check
is_opento verify whether theevent_streamcan be re-used, or needs to be recreated.
So instead the code ends up doing something like:
while event_stream.is_open() { match event_stream.next().await { ... } }
It would enable the utilities from futures, and fit better with the rust async book if Stream was implemented instead. Presumably with Item = Result<types::Event, Error>, which means the event can be handled exactly the same way, with the following changes:
- The loop can be replace with
while let Some(event) = event_stream.next().await { ... }, whilst maintaining access to the error - Errors that mean the stream cannot be continued to be used (probably just websocket closure at this point) can return
None(asStreams returnOption<Self::Item>) - consistent with other Streams, instead of changing a boolean field.
I'll probably end up implementing this in my code as a wrapper around the event_stream, but if you agree this would be a sensible change then I'm happy to discuss the details and raise a PR for the changes.
Metadata
Metadata
Assignees
Labels
No labels