pub struct AsyncComponentSender<C: AsyncComponent> { /* private fields */ }
Expand description

Contains senders to send and receive messages from a Component.

Implementations§

source§

impl<C: AsyncComponent> AsyncComponentSender<C>

source

pub fn input_sender(&self) -> &Sender<C::Input>

Retrieve the sender for input messages.

Useful to forward inputs from another component. If you just need to send input messages, input() is more concise.

source

pub fn output_sender(&self) -> &Sender<C::Output>

Retrieve the sender for output messages.

Useful to forward outputs from another component. If you just need to send output messages, output() is more concise.

source

pub fn command_sender(&self) -> &Sender<C::CommandOutput>

Retrieve the sender for command output messages.

Useful to forward outputs from another component. If you just need to send output messages, command() is more concise.

source

pub fn input(&self, message: C::Input)

Emit an input to the component.

source

pub fn command<Cmd, Fut>(&self, cmd: Cmd)where Cmd: FnOnce(Sender<C::CommandOutput>, ShutdownReceiver) -> Fut + Send + 'static, Fut: Future<Output = ()> + Send,

Spawns an asynchronous command. You can bind the the command to the lifetime of the component by using a ShutdownReceiver.

source

pub fn spawn_command<Cmd>(&self, cmd: Cmd)where Cmd: FnOnce(Sender<C::CommandOutput>) + Send + 'static,

Spawns a synchronous command.

This is particularly useful for CPU-intensive background jobs that need to run on a thread-pool in the background.

If you expect the component to be dropped while the command is running take care while sending messages!

source

pub fn oneshot_command<Fut>(&self, future: Fut)where Fut: Future<Output = C::CommandOutput> + Send + 'static,

Spawns a future that will be dropped as soon as the factory component is shut down.

Essentially, this is a simpler version of Self::command().

source

pub fn spawn_oneshot_command<Cmd>(&self, cmd: Cmd)where Cmd: FnOnce() -> C::CommandOutput + Send + 'static,

Spawns a synchronous command that will be dropped as soon as the factory component is shut down.

Essentially, this is a simpler version of Self::spawn_command().

source§

impl<C: AsyncComponent> AsyncComponentSender<C>

source

pub fn output(&self, message: C::Output) -> Result<(), C::Output>

Emit an output to the component.

Returns Err if all receivers were dropped, for example by detach.

Trait Implementations§

source§

impl<C: AsyncComponent> Clone for AsyncComponentSender<C>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<C: Debug + AsyncComponent> Debug for AsyncComponentSender<C>where C::Input: Debug, C::Output: Debug, C::CommandOutput: Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<C> AsyncPosition<()> for C

source§

fn position(_index: usize)

Returns the position. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

const: unstable · 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<C> Position<()> for C

source§

fn position(&self, _index: usize)

Returns the position. Read more
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.
const: unstable · 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.
const: unstable · source§

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

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more