pub async fn events_receiver(&self) -> Result<Receiver<PublishedEvent>> {
        let (sender, receiver) = unbounded();
        let mut sub = self
            .nc
            .subscribe(&broker::control_event(&self.nsprefix))
            .await?;
        std::thread::spawn(move || loop {
            if let Some(msg) = block_on(&mut sub.next()) {
                match deserialize::<PublishedEvent>(&msg.data) {
                    Ok(evt) => {
                        // If the channel is disconnected, stop sending events
                        if sender.send(evt).is_err() {
                            let _ = block_on(sub.unsubscribe());
                            return;
                        }
                    }
                    _ => error!("Object received on event stream was not a PublishedEvent"),
                }
            }
        });
        Ok(receiver)
    }
/// Returns the receiver end of a channel that subscribes to the lattice control event stream.
/// Any [`PublishedEvent`](struct@PublishedEvent)s that are published after this channel is created
/// will be added to the receiver channel's buffer, which can be observed or handled if needed.
/// See the example for how you could use this receiver to handle events.
///
/// # Example
/// ```rust
/// use wasmcloud_control_interface::Client;
/// async {
///   let nc = nats::asynk::connect("0.0.0.0:4222").await.unwrap();
///   let client = Client::new(nc, None, std::time::Duration::from_millis(1000));
///   let receiver = client.events_receiver().await.unwrap();
///   std::thread::spawn(move || loop {
///     if let Ok(evt) = receiver.recv() {
///       println!("Event received: {:?}", evt);
///     } else {
///       // channel is closed
///       break;
///     }
///   });
///   // perform other operations on client
///   client.get_host_inventory("NAEXHW...").await.unwrap();
/// };
/// ```
///
/// Once you're finished with the event receiver, be sure to call `drop` with the receiver
/// as an argument. This closes the channel and will prevent the sender from endlessly
/// sending messages into the channel buffer.
///
/// # Example
/// ```rust
/// use wasmcloud_control_interface::Client;
/// async {
///   let nc = nats::asynk::connect("0.0.0.0:4222").await.unwrap();
///   let client = Client::new(nc, None, std::time::Duration::from_millis(1000));
///   let receiver = client.events_receiver().await.unwrap();
///   std::thread::spawn(move || {
///     if let Ok(evt) = receiver.recv() {
///       println!("Event received: {:?}", evt);
///       // We received our one event, now close the channel
///       drop(receiver);
///     } else {
///       // channel is closed
///       return;
///     }
///   });
/// };
/// ```
Returns the receiver end of a channel that subscribes to the lattice control event stream.
Any [`PublishedEvent`](struct@PublishedEvent)s that are published after this channel is created
will be added to the receiver channel's buffer, which can be observed or handled if needed.
See the example for how you could use this receiver to handle events.
Returns the receiver end of a channel that subscribes to the lattice control event stream . Any [ ` PublishedEvent ` ] ( struct@PublishedEvent ) s that are published after this channel is created will be added to the receiver channel ' s buffer which can be observed or handled if needed . See the example for how you could use this receiver to handle events .
pub async fn events_receiver(&self) -> Result<Receiver<PublishedEvent>> {
        let (sender, receiver) = unbounded();
        let mut sub = self
            .nc
            .subscribe(&broker::control_event(&self.nsprefix))
            .await?;
        std::thread::spawn(move || loop {
            if let Some(msg) = block_on(&mut sub.next()) {
                match deserialize::<PublishedEvent>(&msg.data) {
                    Ok(evt) => {
                        // If the channel is disconnected, stop sending events
                        if sender.send(evt).is_err() {
                            let _ = block_on(sub.unsubscribe());
                            return;
                        }
                    }
                    _ => error!("Object received on event stream was not a PublishedEvent"),
                }
            }
        });
        Ok(receiver)
    }
pub async fn events_receiver ( & self ) -> Result < Receiver < PublishedEvent > > { let ( sender , receiver ) = unbounded ( ) ; let mut sub = self . nc . subscribe ( & broker :: control_event ( & self . nsprefix ) ) . await ? ; std :: thread :: spawn ( move | | loop { if let Some ( msg ) = block_on ( & mut sub . next ( ) ) { match deserialize :: < PublishedEvent > ( & msg . data ) { Ok ( evt ) => { // If the channel is disconnected, stop sending events if sender . send ( evt ) . is_err ( ) { let _ = block_on ( sub . unsubscribe ( ) ) ; return ; } } _ => error ! ( " " ) , } } } ) ; Ok ( receiver ) }
Returns the receiver end of a channel that subscribes to the lattice control event stream.
Returns the receiver end of a channel that subscribes to the lattice control event stream .
&self
&self
example
```rust
use wasmcloud_control_interface::Client;
async {
let nc = nats::asynk::connect("0.0.0.0:4222").await.unwrap();
let client = Client::new(nc, None, std::time::Duration::from_millis(1000));
let receiver = client.events_receiver().await.unwrap();
std::thread::spawn(move || loop {
if let Ok(evt) = receiver.recv() {
println!("Event received: {:?}", evt);
} else {
channel is closed
break;
}
});
perform other operations on client
client.get_host_inventory("NAEXHW...").await.unwrap();
};
```

Once you're finished with the event receiver, be sure to call `drop` with the receiver
as an argument. This closes the channel and will prevent the sender from endlessly
sending messages into the channel buffer.
` ` ` rust use wasmcloud_control_interface :: Client ; async { let nc = nats :: asynk :: connect ( " 0 . 0 . 0 . 0 : 4222 " ) . await . unwrap () ; let client = Client :: new ( nc None std :: time :: Duration :: from_millis ( 1000 )) ; let receiver = client . events_receiver () . await . unwrap () ; std :: thread :: spawn ( move || loop { if let Ok ( evt ) = receiver . recv () { println! ( " Event received : { : ? } " evt ) ; } else { channel is closed break ; } } ) ; perform other operations on client client . get_host_inventory ( " NAEXHW ... " ) . await . unwrap () ; } ; ` ` ` Once you ' re finished with the event receiver be sure to call ` drop ` with the receiver as an argument . This closes the channel and will prevent the sender from endlessly sending messages into the channel buffer .
example
```rust
use wasmcloud_control_interface::Client;
async {
let nc = nats::asynk::connect("0.0.0.0:4222").await.unwrap();
let client = Client::new(nc, None, std::time::Duration::from_millis(1000));
let receiver = client.events_receiver().await.unwrap();
std::thread::spawn(move || {
if let Ok(evt) = receiver.recv() {
println!("Event received: {:?}", evt);
We received our one event, now close the channel
drop(receiver);
} else {
channel is closed
return;
}
});
};
```
` ` ` rust use wasmcloud_control_interface :: Client ; async { let nc = nats :: asynk :: connect ( " 0 . 0 . 0 . 0 : 4222 " ) . await . unwrap () ; let client = Client :: new ( nc None std :: time :: Duration :: from_millis ( 1000 )) ; let receiver = client . events_receiver () . await . unwrap () ; std :: thread :: spawn ( move || { if let Ok ( evt ) = receiver . recv () { println! ( " Event received : { : ? } " evt ) ; We received our one event now close the channel drop ( receiver ) ; } else { channel is closed return ; } } ) ; } ; ` ` `