[][src]Struct conec::NonblockingInStream

pub struct NonblockingInStream(_);

An adapter to make an InStream non-blocking from the sender's perspective

By default, OutStreams are blocking: receiving client(s) have finite buffering, and once it is full they must drain the buffer before another message can be sent. This can produce undesirable behavior, especially with broadcast streams where some clients are slow to read.

This adapter can be used to prevent the slow receiver problem. Specifically, any client that wraps an InStream with this adapter will automatically read messages into a ring buffer upon arrival. If the ring buffer becomes full, the oldest message will be overwritten. At the next read, the client will get a NonblockingInStreamError::Lagged error indicating that they have missed some number of messages, after which they can resume reading messages from the stream as normal.

Note that to prevent blocking for broadcast streams, all clients must apply this adapter to their InStream. This library does not enforce this---it is up to the application to do so. It is possible to mix nonblocking and blocking clients, e.g., making only the slow clients nonblocking.

This adapter is compatible with tokio-serde's Framed struct, and in particular it should work with any of the tokio_serde::formats codecs. See tests.rs and the crate-level documentation for examples.

Implementations

impl NonblockingInStream[src]

pub fn new(recv: InStream, buflen: usize) -> Self[src]

Create a new NonblockingInStream from a broadcast InStream with a buffer of size buflen

This constructor should only be used for broadcast streams. See also NonblockingInStream::new_unicast.

pub fn new_unicast(recv: InStream, buflen: usize) -> Self[src]

Create a new NonblockingInStream from a unicast InStream with a buffer of size buflen

This constructor should only be used for unicast streams. See also NonblockingInStream::new.

Trait Implementations

impl FusedStream for NonblockingInStream[src]

impl Stream for NonblockingInStream[src]

type Item = Result<BytesMut, NonblockingInStreamError>

Values yielded by the stream.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<St> StreamExt for St where
    St: Stream + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<S> TryStreamExt for S where
    S: TryStream + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,