[][src]Trait async_executors::SpawnHandle

pub trait SpawnHandle<Out: 'static + Send> {
    fn spawn_handle_obj(
        &self,
        future: FutureObj<'static, Out>
    ) -> Result<JoinHandle<Out>, SpawnError>; }

Let's you spawn and get a JoinHandle to await the output of a future.

This trait works much like the Spawn trait from the futures library. It takes a FutureObj so we can hopefully make it no_std compatible when needed. This also allows it to be object safe. For convenience, there is SpawnHandleExt which allows you to spawn a generic future directly without having to manually make the FutureObj.

SpawnHandleExt is automatically implemented but must be in scope, so this works:

use async_executors::{ SpawnHandle, SpawnHandleExt };

async fn need_exec( exec: impl SpawnHandle<()> )
{
   let join_handle = exec.spawn_handle( async {} ).expect( "spawn" );

   join_handle.await;
}

and so does this:

use async_executors::{ SpawnHandle, SpawnHandleExt };

async fn need_exec( exec: Box< dyn SpawnHandle<()> > )
{
   let join_handle = exec.spawn_handle( async {} ).expect( "spawn" );

   join_handle.await;
}

One inconvenience of it having to be object safe is that the trait needs to be generic over the output parameter. This can be annoying if you need an executor that can spawn futures with different output parameters. Normally you should always be able to know which ones you need. If not you will have to make the type that stores the executor generic over the output type as well.

So to enable several output types you can use the following workaround.

Required methods

fn spawn_handle_obj(
    &self,
    future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>

Spawn a future and return a JoinHandle that can be awaited for the output of the future.

Loading content...

Implementations on Foreign Types

impl<T, Out> SpawnHandle<Out> for Instrumented<T> where
    T: SpawnHandle<Out>,
    Out: 'static + Send
[src]

impl<T, Out> SpawnHandle<Out> for WithDispatch<T> where
    T: SpawnHandle<Out>,
    Out: 'static + Send
[src]

impl<T: ?Sized, Out> SpawnHandle<Out> for Box<T> where
    T: SpawnHandle<Out>,
    Out: 'static + Send
[src]

impl<T: ?Sized, Out> SpawnHandle<Out> for Arc<T> where
    T: SpawnHandle<Out>,
    Out: 'static + Send
[src]

impl<T: ?Sized, Out> SpawnHandle<Out> for Rc<T> where
    T: SpawnHandle<Out>,
    Out: 'static + Send
[src]

impl<'_, T, Out> SpawnHandle<Out> for &'_ T where
    T: SpawnHandle<Out>,
    Out: 'static + Send
[src]

impl<'_, T, Out> SpawnHandle<Out> for &'_ mut T where
    T: SpawnHandle<Out>,
    Out: 'static + Send
[src]

Loading content...

Implementors

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

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

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

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

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

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

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

Loading content...