[][src]Struct async_executors::TokioCt

pub struct TokioCt { /* fields omitted */ }
This is supported on feature="tokio_ct" only.

An executor that uses a tokio::runtime::Runtime with the basic scheduler. Can spawn !Send futures.

You must make sure that calls to spawn and spawn_local happen in async context, withing a task running on TokioCt::block_on.

You can obtain a wrapper to tokio::runtime::handle through TokioCt::handle. That can be used to send a future from another thread to run on the TokioCt executor.

Unwind Safety.

When a future spawned on this wrapper panics, the thread will unwind until the block_on, not above.

You must only spawn futures to this API that are unwind safe. Tokio will wrap the task running from block_on 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 task. 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 top level task has unwound, nor any destructors called during the unwind can observe data in an inconsistent state.

Note that these are logic errors, not related to the class of problems that cannot happen in safe rust (memory safety, undefined behavior, unsoundness, data races, ...). See the relevant catch_unwind RFC and it's discussion threads for more info as well as the documentation in std::panic::UnwindSafe for more information.

Methods

impl TokioCt[src]

pub fn block_on<F: Future>(&mut self, f: F) -> F::Output[src]

This is the entry point for this executor. You must call spawn from within a future that is running through block_on. Once this call returns, no remaining tasks shall be polled anymore. However the tasks stay in the executor, so if you make a second call to block_on with a new task, the older tasks will start making progress again.

For simplicity, it's advised to just create top level task that you run through block_on and make sure your program is done when it returns.

pub fn handle(&self) -> TokioHandle[src]

Obtain a handle to this executor that can easily be cloned and that implements the Spawn trait.

Note that this handle is Send and can be sent to another thread to spawn tasks on the current executor, but as such, tasks are required to be Send.

Trait Implementations

impl Clone for TokioCt[src]

impl Debug for TokioCt[src]

impl LocalSpawn for TokioCt[src]

impl<Out: 'static> LocalSpawnHandle<Out> for TokioCt[src]

impl Spawn for TokioCt[src]

impl<Out: 'static + Send> SpawnHandle<Out> for TokioCt[src]

impl<'_> TryFrom<&'_ mut Builder> for TokioCt[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

impl !RefUnwindSafe for TokioCt

impl !Send for TokioCt

impl !Sync for TokioCt

impl Unpin for TokioCt

impl !UnwindSafe for TokioCt

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[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> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<Sp> LocalSpawnExt for Sp where
    Sp: LocalSpawn + ?Sized
[src]

impl<Sp> SpawnExt for Sp where
    Sp: Spawn + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.

impl<T> WithSubscriber for T[src]