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>::Output: 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::ready::<u32>(1);
let join_handle = block_on(spawn_with_handle(future));
let output = block_on(join_handle);
assert_eq!(output, 1);