Function bitcoincore_zmq::subscribe_async

source ยท
pub fn subscribe_async(endpoints: &[&str]) -> Result<MessageStream, Error>
Available on crate feature async only.
Expand description

Subscribes to multiple ZMQ endpoints and returns a stream that produces Messages.

Examples found in repository?
examples/subscribe_async.rs (line 6)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fn main() {
    let mut stream = subscribe_async(&["tcp://127.0.0.1:28332"]).unwrap();

    // This is a small example to demonstrate subscribe_single_async, it is okay here to use
    // block_on, but not in production environments as this defeats the purpose of async.
    block_on(async {
        while let Some(msg) = stream.next().await {
            match msg {
                Ok(msg) => println!("Received message: {msg}"),
                Err(err) => println!("Error receiving message: {err}"),
            }
        }
    });
}