Function futures::executor::spawn_with_handle [] [src]

pub fn spawn_with_handle<F>(f: F) -> SpawnWithHandle<F> where
    F: Future + 'static + Send,
    <F as Future>::Item: Send,
    <F as Future>::Error: Send

Spawn a task onto the default executor, yielding a JoinHandle to the spawned task.

This function returns a future that will spawn the given future as a task onto the default executor. On completion, that future will yield a JoinHandle that can itself be used as a future representing the completion of the spawned task.

Examples

use futures::prelude::*;
use futures::future;
use futures::executor::{block_on, spawn_with_handle};

let future = future::ok::<u32, Never>(1);
let join_handle = block_on(spawn_with_handle(future))?;
let result = block_on(join_handle);
assert_eq!(result, Ok(1));
use futures::prelude::*;
use futures::future;
use futures::executor::{block_on, spawn_with_handle};

let future = future::err::<Never, &str>("boom");
let join_handle = block_on(spawn_with_handle(future))?;
let result = block_on(join_handle);
assert_eq!(result, Err("boom"));