bitcoincore_zmq/subscribe/
blocking.rs

1use super::{new_socket_internal, subscribe_internal};
2use crate::{error::Result, message::Message};
3use core::{convert::Infallible, ops::ControlFlow};
4
5/// Subscribes to a single ZMQ endpoint and blocks the thread until [`ControlFlow::Break`] is
6/// returned by the callback.
7#[inline]
8#[deprecated(
9    since = "1.3.2",
10    note = "Use subscribe_blocking. This function has no performance benefit over subscribe_multi_blocking anymore."
11)]
12pub fn subscribe_single_blocking<F, B>(
13    endpoint: &str,
14    callback: F,
15) -> Result<ControlFlow<B, Infallible>>
16where
17    F: Fn(Result<Message>) -> ControlFlow<B>,
18{
19    subscribe_blocking(&[endpoint], callback)
20}
21
22/// Subscribes to multiple ZMQ endpoints and blocks the thread until [`ControlFlow::Break`] is
23/// returned by the callback.
24#[inline]
25#[deprecated(
26    since = "1.3.2",
27    note = "Use subscribe_blocking. The name changed because there is no distinction made anymore between subscribing to 1 or more endpoints."
28)]
29pub fn subscribe_multi_blocking<F, B>(
30    endpoints: &[&str],
31    callback: F,
32) -> Result<ControlFlow<B, Infallible>>
33where
34    F: Fn(Result<Message>) -> ControlFlow<B>,
35{
36    subscribe_blocking(endpoints, callback)
37}
38
39/// Subscribes to multiple ZMQ endpoints and blocks the thread until [`ControlFlow::Break`] is
40/// returned by the callback.
41#[inline]
42pub fn subscribe_blocking<F, B>(
43    endpoints: &[&str],
44    callback: F,
45) -> Result<ControlFlow<B, Infallible>>
46where
47    F: Fn(Result<Message>) -> ControlFlow<B>,
48{
49    let (_context, socket) = new_socket_internal(endpoints)?;
50
51    Ok(subscribe_internal(socket, callback))
52}