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.
Motivation
Currently, to return an SSE response the
tokio
feature is required, even though Tokio runtime is only needed for timeouts to maintain keep-alive connection. This limitation restricts the use of SSE with other runtimes.Solution
The
KeepAliveStream
now wraps aStream<Item = Result<Event, _>>
and implementsStream<Item = Result<Event, _>>
itself to maintain the keep-alive connection. This feature is optional and users can choose not to use keep-alive or implement their own wrapper if needed.The keep-alive message itself is now represented by the
Event
type, making it more convenient to wrap a user-definedStream<Item = Result<Event, _>>
. If a user wants to implement their own wrapper, they can useEvent::DEFAULT_KEEP_ALIVE
, which is a cheap to clone default keep-alive message.Impl #3153