[][src]Trait xtra::prelude::MessageChannelExt

pub trait MessageChannelExt<M: Message> {
    fn is_connected(&self) -> bool;
fn do_send(&self, message: M) -> Result<(), Disconnected>;
fn send(&self, message: M) -> MessageResponseFuture<M>;
fn attach_stream<S>(self, stream: S)
    where
        S: Stream<Item = M> + Send + Unpin + 'static,
        Self: Sized + Send + Sink<M, Error = Disconnected> + 'static
; }

General trait for any kind of channel of messages, be it strong or weak. This trait contains all functions of the channel.

Required methods

fn is_connected(&self) -> bool

Returns whether the actor referred to by this address is running and accepting messages.

fn do_send(&self, message: M) -> Result<(), Disconnected>

Sends a Message to the actor, and does not wait for a response. If this returns Err(Disconnected), then the actor is stopped and not accepting messages. If this returns Ok(()), the will be delivered, but may not be handled in the event that the actor stops itself (by calling Context::stop) before it was handled.

fn send(&self, message: M) -> MessageResponseFuture<M>

Sends a Message to the actor, and waits for a response. If this returns Err(Disconnected), then the actor is stopped and not accepting messages.

fn attach_stream<S>(self, stream: S) where
    S: Stream<Item = M> + Send + Unpin + 'static,
    Self: Sized + Send + Sink<M, Error = Disconnected> + 'static, 

This is supported on feature="with-tokio-0_2" and feature="with-async_std-1" and feature="with-wasm_bindgen-0_2" and feature="with-smol-0_1" only.

Attaches a stream to this channel such that all messages produced by it are forwarded to the actor. This could, for instance, be used to forward messages from a socket to the actor (after the messages have been appropriately mapped). This is a convenience method over explicitly forwarding a stream to this address, spawning that future onto the executor, and mapping the error away (because disconnects are expected and will simply mean that the stream is no longer being forwarded).

Note: if this stream's continuation should prevent the actor from being dropped, this method should be called on MessageChannel. Otherwise, it should be called on WeakMessageChannel.

Loading content...

Implementors

impl<M: Message> MessageChannelExt<M> for MessageChannel<M>[src]

impl<M: Message> MessageChannelExt<M> for WeakMessageChannel<M>[src]

Loading content...