spawn

Function spawn 

Source
pub fn spawn<F>(f: F)
where F: Future<Item = (), Error = ()> + 'static,
Expand description

Spawn a future to the current main loop

This only works if running inside the run() function of the main loop

This is an equivalent of:

handle().spawn(f)

§Panics

This function panics if there is no currently running loop (i.e. this function is not running from the inside of run().

Examples found in repository?
examples/two_intervals.rs (lines 11-15)
8fn main() {
9
10    run_forever(|| {
11        spawn(interval(Duration::new(1, 0))
12            .for_each(|()| {
13                println!("1 sec interval");
14                Ok(())
15            }).map_err(|_| ()));
16        spawn(interval(Duration::from_millis(500))
17            .for_each(|()| {
18                println!("Half second interval");
19                Ok(())
20            }).map_err(|_| ()));
21        Ok::<_, ()>(())
22    }).unwrap();
23}