1 | //! The `stream_select` macro. |
2 | |
3 | #[cfg (feature = "std" )] |
4 | #[allow (unreachable_pub)] |
5 | #[doc (hidden)] |
6 | pub use futures_macro::stream_select_internal; |
7 | |
8 | /// Combines several streams, all producing the same `Item` type, into one stream. |
9 | /// This is similar to `select_all` but does not require the streams to all be the same type. |
10 | /// It also keeps the streams inline, and does not require `Box<dyn Stream>`s to be allocated. |
11 | /// Streams passed to this macro must be `Unpin`. |
12 | /// |
13 | /// If multiple streams are ready, one will be pseudo randomly selected at runtime. |
14 | /// |
15 | /// # Examples |
16 | /// |
17 | /// ``` |
18 | /// # futures::executor::block_on(async { |
19 | /// use futures::{stream, StreamExt, stream_select}; |
20 | /// let endless_ints = |i| stream::iter(vec![i].into_iter().cycle()).fuse(); |
21 | /// |
22 | /// let mut endless_numbers = stream_select!(endless_ints(1i32), endless_ints(2), endless_ints(3)); |
23 | /// match endless_numbers.next().await { |
24 | /// Some(1) => println!("Got a 1" ), |
25 | /// Some(2) => println!("Got a 2" ), |
26 | /// Some(3) => println!("Got a 3" ), |
27 | /// _ => unreachable!(), |
28 | /// } |
29 | /// # }); |
30 | /// ``` |
31 | #[cfg (feature = "std" )] |
32 | #[macro_export ] |
33 | macro_rules! stream_select { |
34 | ($($tokens:tt)*) => {{ |
35 | use $crate::__private as __futures_crate; |
36 | $crate::stream_select_internal! { |
37 | $( $tokens )* |
38 | } |
39 | }} |
40 | } |
41 | |