Struct stakker::sync::Channel

source ·
pub struct Channel<M: Send> { /* private fields */ }
Expand description

Channel for sending messages to an actor

A Channel may be used to send messages of type M to an actor from any thread. It is an unbounded queue.

Messages are delivered directly to an actor method via a Fwd instance. Cleanup of the channel is handled via a ChannelGuard which should be kept in the same actor. When this is dropped, the channel is closed, and senders are informed via the Channel::send and Channel::is_closed methods. So this handles cleanup automatically when the actor fails or terminates for any reason.

Implementations§

source§

impl<M: Send> Channel<M>

source

pub fn new(core: &mut Core, fwd: Fwd<M>) -> (Self, ChannelGuard)

Create a new channel that directs messages to an actor using the given Fwd instance. Returns the channel and a channel-guard. The Channel may be cloned as many times as necessary and sent to other threads. The ChannelGuard should be kept in the actor that receives the messages.

source

pub fn send(&self, msg: M) -> bool

Send a message to destination actor in the Stakker thread if the channel is open, and return true. If the channel has been closed, returns false.

source

pub fn is_closed(&self) -> bool

Tests whether the channel has been closed.

Trait Implementations§

source§

impl<M: Send> Clone for Channel<M>

source§

fn clone(&self) -> Self

Get another reference to the same channel

1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<M> RefUnwindSafe for Channel<M>

§

impl<M> Send for Channel<M>

§

impl<M> Sync for Channel<M>

§

impl<M> Unpin for Channel<M>

§

impl<M> UnwindSafe for Channel<M>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

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

§

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.