1use async_stream::stream;
2use futures_util::pin_mut;
3use futures_util::stream::StreamExt;
4use tokio::net::TcpListener;
5
6#[tokio::main]
7async fn main() {
8 let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
9
10 let incoming = stream! {
11 loop {
12 let (socket, _) = listener.accept().await.unwrap();
13 yield socket;
14 }
15 };
16 pin_mut!(incoming);
17
18 while let Some(v) = incoming.next().await {
19 println!("handle = {:?}", v);
20 }
21}
22