[−][src]Trait async_executors::SpawnHandle
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
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&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.
Implementations on Foreign Types
impl<T, Out> SpawnHandle<Out> for Instrumented<T> where
T: SpawnHandle<Out>,
Out: 'static + Send, [src]
T: SpawnHandle<Out>,
Out: 'static + Send,
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
impl<T, Out> SpawnHandle<Out> for WithDispatch<T> where
T: SpawnHandle<Out>,
Out: 'static + Send, [src]
T: SpawnHandle<Out>,
Out: 'static + Send,
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
impl<T: ?Sized, Out> SpawnHandle<Out> for Box<T> where
T: SpawnHandle<Out>,
Out: 'static + Send, [src]
T: SpawnHandle<Out>,
Out: 'static + Send,
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
impl<T: ?Sized, Out> SpawnHandle<Out> for Arc<T> where
T: SpawnHandle<Out>,
Out: 'static + Send, [src]
T: SpawnHandle<Out>,
Out: 'static + Send,
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
impl<T: ?Sized, Out> SpawnHandle<Out> for Rc<T> where
T: SpawnHandle<Out>,
Out: 'static + Send, [src]
T: SpawnHandle<Out>,
Out: 'static + Send,
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
impl<T, Out> SpawnHandle<Out> for &T where
T: SpawnHandle<Out>,
Out: 'static + Send, [src]
T: SpawnHandle<Out>,
Out: 'static + Send,
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
impl<T, Out> SpawnHandle<Out> for &mut T where
T: SpawnHandle<Out>,
Out: 'static + Send, [src]
T: SpawnHandle<Out>,
Out: 'static + Send,
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
Implementors
impl<Out: 'static + Send> SpawnHandle<Out> for AsyncGlobal[src]
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
impl<Out: 'static + Send> SpawnHandle<Out> for AsyncStd[src]
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
impl<Out: 'static + Send> SpawnHandle<Out> for Bindgen[src]
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
impl<Out: 'static + Send> SpawnHandle<Out> for LocalSpawner[src]
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
impl<Out: 'static + Send> SpawnHandle<Out> for ThreadPool[src]
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
impl<Out: 'static + Send> SpawnHandle<Out> for TokioCt[src]
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>
impl<Out: 'static + Send> SpawnHandle<Out> for TokioTp[src]
pub fn spawn_handle_obj(
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>[src]
&self,
future: FutureObj<'static, Out>
) -> Result<JoinHandle<Out>, SpawnError>