[−][src]Struct stakker::PipedThread
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 andfwd_term
is called with the panic error, orNone
if there was no panic. This handler can discard thePipedThread
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 thePipedThread
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]
core: &mut Core,
fwd_recv: Fwd<I>,
fwd_term: Fwd<Option<String>>,
run: impl FnOnce(&mut PipedLink<O, I>) + Send + 'static
) -> Self
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]
T: 'static + ?Sized,
impl<T> Any for T where
T: Any,
[src]
T: Any,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,