Skip to content

Instantly share code, notes, and snippets.

@octave99
Created April 29, 2019 13:10
Show Gist options
  • Save octave99/d7b7a13856b0955db3e74d50c59095f5 to your computer and use it in GitHub Desktop.
Save octave99/d7b7a13856b0955db3e74d50c59095f5 to your computer and use it in GitHub Desktop.
use futures::future::{Future, ok, select_ok}; // 0.1.26
use tokio; // 0.1.18
use tokio_timer::sleep; // 0.2.10
use std::time::Duration;
fn i() -> impl Future<Item=(), Error=()> {
print!("Immediate\n");
ok(())
}
fn d() -> impl Future<Item=(), Error=()> {
sleep(Duration::from_millis(3000)).and_then(|_|{
print!("Delayed\n");
ok(())
}).map_err(|_| ())
}
fn main(){
// Exits on completion of immediate and prints only Immediate
// let fut = i().select(d()).then(|_| ok(()));
// Waits for both the futures to complete and prints both Immediate and Delayed
let fut = i().join(d()).map(|_| ());
tokio::run(fut);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment