subscribe_async/subscribe_async.rs
1use bitcoincore_zmq::subscribe_async;
2use futures::executor::block_on;
3use futures_util::StreamExt;
4
5fn main() {
6 let mut stream = subscribe_async(&["tcp://127.0.0.1:28332"]).unwrap();
7
8 // This is a small example to demonstrate subscribe_single_async, it is okay here to use
9 // block_on, but not in production environments as this defeats the purpose of async.
10 block_on(async {
11 while let Some(msg) = stream.next().await {
12 match msg {
13 Ok(msg) => println!("Received message: {msg}"),
14 Err(err) => println!("Error receiving message: {err}"),
15 }
16 }
17 });
18}