[−][src]Struct async_executors::TokioHandle
A handle to a TokioCt or TokioTp executor. It implements Spawn
and SpawnHandle
traits.
You can obtain one from TokioCt::handle or TokioTp::handle.
For TokioTp this can be used to avoid a drop order problem for the tokio Runtime. See the documentation for TokioTp for an explanation.
For TokioCt this can be used to send a future from another thread to run on the TokioCt.
The handle is only operational as long as the parent executor is alive. There is no compiler
assisted lifetime tracking for this as generally spawned futures you would like to give the
handle to need to be 'static
, so usability would be rather hampered. You must make
sure you manage the lifetimes manually.
If the parent executor is already dropped when spawn is called, the future just get's dropped silently without ever being polled.
Unwind Safety.
You must only spawn futures to this API that are unwind safe. Tokio will wrap it in std::panic::AssertUnwindSafe and wrap the poll invocation with std::panic::catch_unwind.
They reason that this is fine because they require Send + 'static
on the future. As far
as I can tell this is wrong. Unwind safety can be circumvented in several ways even with
Send + 'static
(eg. parking_lot::Mutex
is Send + 'static
but !UnwindSafe
).
You should make sure that if your future panics, no code that lives on after the spawned task has unwound, nor any destructors called during the unwind can observe data in an inconsistent state.
See the relevant catch_unwind RFC and it's discussion threads for more info as well as the documentation of std::panic::UnwindSafe.
Trait Implementations
impl Clone for TokioHandle
[src]
fn clone(&self) -> TokioHandle
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for TokioHandle
[src]
impl Spawn for TokioHandle
[src]
fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError>
[src]
fn status(&self) -> Result<(), SpawnError>
[src]
impl<Out: 'static + Send> SpawnHandle<Out> for TokioHandle
[src]
fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
Auto Trait Implementations
impl !RefUnwindSafe for TokioHandle
impl Send for TokioHandle
impl Sync for TokioHandle
impl Unpin for TokioHandle
impl !UnwindSafe for TokioHandle
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<Sp> SpawnExt for Sp where
Sp: Spawn + ?Sized,
[src]
Sp: Spawn + ?Sized,
fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError> where
Fut: Future<Output = ()> + Send + 'static,
[src]
Fut: Future<Output = ()> + Send + 'static,
fn spawn_with_handle<Fut>(
&self,
future: Fut
) -> Result<RemoteHandle<<Fut as Future>::Output>, SpawnError> where
Fut: Future + Send + 'static,
<Fut as Future>::Output: Send,
[src]
&self,
future: Fut
) -> Result<RemoteHandle<<Fut as Future>::Output>, SpawnError> where
Fut: Future + Send + 'static,
<Fut as Future>::Output: Send,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> WithSubscriber for T
[src]
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]
S: Into<Dispatch>,