Skip to main content

EventStream

Struct EventStream 

Source
pub struct EventStream<I: Input> { /* private fields */ }
Expand description

A thread-backed [futures_core::Stream] of io::Result<Event> over a shared EventSource.

Build one with EventSource::into_stream (sole owner) or EventStream::from_shared (sharing a source kept elsewhere). A helper thread waits for readiness or a decode deadline, then wakes the polling task. The task drains queued events and decodes through a non-blocking poll. A private notification handle refreshes waits after deadline changes. The stream yields Some(Ok(event)) for each event. It reports an input or readiness error once as Some(Err(_)), then fuses to None. Dropping it ends the helper thread; the shared source is left intact for any other holder.

Source wakes request another readiness pass. Ready events leave wakes pending; a wake alone keeps the stream pending. Use a separate async signal for cancellation.

Implementations§

Source§

impl<I> EventStream<I>
where I: Input + 'static,

Source

pub fn from_shared(source: Arc<Mutex<EventSource<I>>>) -> Self

Build a stream over a source shared via Arc<Mutex<_>>.

The caller may keep its own clone of the Arc to read the source synchronously while the stream is live (see the coexistence caveats on this module).

Trait Implementations§

Source§

impl<I: Input> Drop for EventStream<I>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<I: Input> Stream for EventStream<I>

Source§

type Item = Result<Event, Error>

Values yielded by the stream.
Source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>

Attempt to pull out the next value of this stream, registering the current task for wakeup if the value is not yet available, and returning None if the stream is exhausted. Read more
§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream. Read more

Auto Trait Implementations§

§

impl<I> Freeze for EventStream<I>

§

impl<I> RefUnwindSafe for EventStream<I>

§

impl<I> Send for EventStream<I>

§

impl<I> Sync for EventStream<I>

§

impl<I> Unpin for EventStream<I>

§

impl<I> UnsafeUnpin for EventStream<I>

§

impl<I> UnwindSafe for EventStream<I>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<S, T, E> TryStream for S
where S: Stream<Item = Result<T, E>> + ?Sized,

§

type Ok = T

The type of successful values yielded by this future
§

type Error = E

The type of failures yielded by this future
§

fn try_poll_next( self: Pin<&mut S>, cx: &mut Context<'_>, ) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>>

Poll this TryStream as if it were a Stream. Read more