pub fn subscribe_blocking<F, B>(
endpoints: &[&str],
callback: F,
) -> Result<ControlFlow<B, Infallible>, Error>
Expand description
Subscribes to multiple ZMQ endpoints and blocks the thread until ControlFlow::Break
is
returned by the callback.
Examples found in repository?
examples/subscribe_blocking.rs (line 17)
4fn main() {
5 let callback = |msg| {
6 match msg {
7 Ok(msg) => println!("Received message: {msg}"),
8 Err(err) => {
9 // Do this to exit and return the error
10 return ControlFlow::Break(err);
11 }
12 }
13
14 ControlFlow::Continue(())
15 };
16
17 match subscribe_blocking(&["tcp://127.0.0.1:28359"], callback) {
18 Ok(ControlFlow::Break(err)) => {
19 // Callback exited by returning ControlFlow::Break
20 println!("Error receiving message: {err}");
21 }
22 Err(err) => {
23 println!("Unable to connect: {err}");
24 }
25 Ok(ControlFlow::Continue(v)) => {
26 // unreachable
27 match v {}
28 }
29 }
30}