Skip to main content

Receiver

Struct Receiver 

Source
pub struct Receiver { /* private fields */ }
Expand description

The consuming half of a session: the only way to observe completions.

Not clonable. The ordering the completion ring promises – every entry of one enumeration before its terminal – is a statement about one observer, and two receivers racing on the same ring would each see an arbitrary subsequence of it.

Dropping the receiver abandons the session: the session stops accepting enumerations and releases the ones it is carrying, without delivering any terminal outcome, because no observer remains to owe one to.

Implementations§

Source§

impl Receiver

Source

pub fn try_recv(&self) -> Option<Completion>

Take the next record if one is already queued.

Source

pub fn recv(&self) -> Option<Completion>

Block until a record is available, or until the stream ends.

Returns None only when nothing is queued, no session handle remains, and no enumeration is still outstanding.

Source

pub fn recv_timeout(&self, timeout: Duration) -> Option<Completion>

Block for at most timeout.

Returns None on timeout as well as at the end of the stream; a caller that must tell them apart can check is_disconnected.

Source

pub fn doorbell(&self) -> Result<BorrowedHandle<'_>>

A manual-reset event, signalled exactly while this receiver has something to take.

This is what lets a client integrate with its own thread pool instead of dedicating a thread to recv: wait on the handle, then drain with try_recv until it yields None. It stays signalled once the stream has ended, so a waiter learns about that too.

The event is created on the first call, so a client that never asks for it pays for no kernel object. The borrow is deliberate: the event belongs to the ring and must not be closed by a caller.

§Errors

Returns the error from CreateEventW on the first call.

Source

pub fn doorbell_owned(&self) -> Result<OwnedHandle>

A duplicate of doorbell that the caller owns, as arming a ThreadpoolWait requires.

§Errors

Returns the error from CreateEventW or DuplicateHandle.

Source

pub fn is_disconnected(&self) -> bool

Whether the stream has ended.

Source

pub fn len(&self) -> usize

How many records are queued right now.

Source

pub fn is_empty(&self) -> bool

Whether nothing is queued right now.

Source

pub fn capacity(&self) -> usize

The completion ring’s bound.

Trait Implementations§

Source§

impl Debug for Receiver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Receiver

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

Auto Trait Implementations§

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
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, 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, <T as TryFrom<U>>::Error>

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.