[][src]Struct stakker::PipedThread

pub struct PipedThread<O: Send + Sync + 'static, I: Send + Sync + 'static> { /* fields omitted */ }

A thread connected to the actor runtime via channels

This takes care of starting a thread and transferring data to and from it via channels. Data sent to the thread has type O, and data received has type I. These would often be enums to handle different kinds of data (e.g. messages, commands or responses as required).

Cleanup is handled as follows:

  • If the thread terminates normally or panics, then the underlying Waker notifies the main thread and fwd_term is called with the panic error, or None if there was no panic. This handler can discard the PipedThread instance to complete the cleanup, and start a new thread if necessary.

  • If the PipedThread instance is dropped in the main thread, then a cancel flag is set which the thread will notice next time it tries to send or receive data. The thread should then terminate. So if the PipedThread instance is kept within the same actor that is handling the incoming data, then this takes care of thread cleanup automatically if the actor fails unexpectedly.

Methods

impl<O: Send + Sync + 'static, I: Send + Sync + 'static> PipedThread<O, I>[src]

pub fn spawn(
    core: &mut Core,
    fwd_recv: Fwd<I>,
    fwd_term: Fwd<Option<String>>,
    run: impl FnOnce(&mut PipedLink<O, I>) + Send + 'static
) -> Self
[src]

pub fn send(&mut self, msg: O)[src]

Send a message to the thread. If the thread is blocked on receive, wake it.

Auto Trait Implementations

impl<O, I> !RefUnwindSafe for PipedThread<O, I>

impl<O, I> Send for PipedThread<O, I>

impl<O, I> Sync for PipedThread<O, I>

impl<O, I> Unpin for PipedThread<O, I>

impl<O, I> !UnwindSafe for PipedThread<O, I>

Blanket Implementations

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

impl<T> Any for T where
    T: Any
[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, 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.