run_forever

Function run_forever 

Source
pub fn run_forever<F: FnOnce() -> Result<(), E>, E>(f: F) -> Result<(), E>
Expand description

Run the main loop and initialize it by running a function, which spawns more futures in the main loop. Then run loop indefinitely.

This is basically a shortcut for:

let mut lp = Core::new().expect("create loop");
lp.run(futures::lazy(f)
       .and_then(|_| empty()))

The difference between run() and run_forever() is merely a convenience. Basically, you want to use run() in client applications when you have a future that should complete to proceed. And run_forever() in server applications which spawns some listeners and never exits.

But also initializes thread-local loop handle for the time of loop run

Examples found in repository?
examples/two_intervals.rs (lines 10-22)
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}