Advertisement
NLinker

select! example

Nov 13th, 2019
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.56 KB | None | 0 0
  1. use std::error::Error;
  2. use futures::{future, select}; // futures-0.3.1
  3. use futures::executor::block_on;
  4.  
  5. fn main() -> Result<(), Box<dyn Error>> {
  6.  
  7.     let ts: [(i32, i32); 3] = [(1, 10), (2, 20), (3, 30)];
  8.  
  9.     for t in &ts {
  10.         let mut a = future::ready(t.0);
  11.         let mut b = future::pending::<()>();
  12.         block_on(async {
  13.             let got = select! {
  14.                     got = a => got + t.1,
  15.                     _   = b => 0,
  16.                 };
  17.             eprintln!("got, t.0, t.1: {} {} {}", got, t.0, t.1);
  18.         })
  19.     }
  20.     Ok(())
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement