pub struct SseStream { /* private fields */ }Expand description
Streaming HTTP body that serializes SseEvents from an mpsc channel.
Implements http_body::Body so it can be carried as FerroBody::Stream through the
framework’s hyper serve loop. The stream ends when the mpsc::Sender is dropped.
A :ping\n\n keep-alive comment is emitted every 15 seconds while the channel is idle.
Any real event resets the idle window.
§Bounded back-pressure
The internal channel is bounded (default 16 slots via SseStream::channel). If the
client is too slow, Sender::send().await will apply back-pressure to the producer.
§Connection count limits
Each active SseStream holds a TCP connection open. Connection-count limits are the
application’s responsibility, not this primitive’s.
Implementations§
Source§impl SseStream
impl SseStream
Sourcepub fn channel(buffer: usize) -> (Sender<SseEvent>, Self)
pub fn channel(buffer: usize) -> (Sender<SseEvent>, Self)
Create a bounded channel for pushing events and the streaming body.
Returns (sender, stream). The handler holds the sender and pushes events from
a spawned task; the stream is wrapped in an HttpResponse::sse response.
Uses interval_at with an initial delay equal to interval_period so that
the first ping is deferred — avoiding an immediate :ping frame on connection.
Trait Implementations§
Source§impl Body for SseStream
impl Body for SseStream
Source§type Error = Infallible
type Error = Infallible
Body might generate.Source§fn poll_frame(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Frame<Bytes>, Self::Error>>>
fn poll_frame( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Frame<Bytes>, Self::Error>>>
Source§fn is_end_stream(&self) -> bool
fn is_end_stream(&self) -> bool
true when the end of stream has been reached. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for SseStream
impl !UnwindSafe for SseStream
impl Freeze for SseStream
impl Send for SseStream
impl Sync for SseStream
impl Unpin for SseStream
impl UnsafeUnpin for SseStream
Blanket Implementations§
Source§impl<T> BodyExt for T
impl<T> BodyExt for T
Source§fn frame(&mut self) -> Frame<'_, Self>where
Self: Unpin,
fn frame(&mut self) -> Frame<'_, Self>where
Self: Unpin,
Frame, if any.Source§fn map_frame<F, B>(self, f: F) -> MapFrame<Self, F>
fn map_frame<F, B>(self, f: F) -> MapFrame<Self, F>
Source§fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
Source§fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
Source§fn collect(self) -> Collect<Self>where
Self: Sized,
fn collect(self) -> Collect<Self>where
Self: Sized,
Collected body which will collect all the DATA frames
and trailers.Source§fn with_trailers<F>(self, trailers: F) -> WithTrailers<Self, F>
fn with_trailers<F>(self, trailers: F) -> WithTrailers<Self, F>
Source§fn into_data_stream(self) -> BodyDataStream<Self>where
Self: Sized,
fn into_data_stream(self) -> BodyDataStream<Self>where
Self: Sized,
BodyDataStream.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more