pub struct WsNotifyChannel { /* private fields */ }
Expand description
Represents a Catenis WebSocket notification channel.
This is used to receive notifications from the Catenis system.
An instance of this object should be obtained from a CatenisClient
object via its
new_ws_notify_channel
method.
Implementations§
Source§impl WsNotifyChannel
impl WsNotifyChannel
Sourcepub fn open<F>(&mut self, notify_event_handler: F) -> Result<JoinHandle<()>>
pub fn open<F>(&mut self, notify_event_handler: F) -> Result<JoinHandle<()>>
Open the WebSocket notification channel setting up a handler to monitor the activity on that channel.
Note: this is a non-blocking operation. The provided handler function is run on its own thread.
§Example
use std::sync::{Arc, Mutex};
use catenis_api_client::{
CatenisClient, ClientOptions, Environment, Result,
api::NotificationEvent,
notification::WsNotifyChannelEvent,
};
let ctn_client = CatenisClient::new_with_options(
Some((
"drc3XdxNtzoucpw9xiRp",
concat!(
"4c1749c8e86f65e0a73e5fb19f2aa9e74a716bc22d7956bf3072b4bc3fbfe2a0",
"d138ad0d4bcfee251e4e5f54d6e92b8fd4eb36958a7aeaeeb51e8d2fcc4552c3"
),
).into()),
&[
ClientOptions::Environment(Environment::Sandbox),
],
)?;
// Instantiate WebSocket notification channel object for New Message Received
// notification event
let notify_channel = Arc::new(Mutex::new(
ctn_client.new_ws_notify_channel(NotificationEvent::NewMsgReceived)
));
let notify_channel_2 = notify_channel.clone();
let notify_thread = notify_channel.lock().unwrap()
// Open WebSocket notification channel and monitor events on it
.open(move |event: WsNotifyChannelEvent| {
let notify_channel = notify_channel_2.lock().unwrap();
match event {
WsNotifyChannelEvent::Error(err) => {
println!("WebSocket notification channel error: {:?}", err);
},
WsNotifyChannelEvent::Open => {
println!("WebSocket notification channel open");
},
WsNotifyChannelEvent::Close(close_info) => {
println!("WebSocket notification channel closed: {:?}", close_info);
},
WsNotifyChannelEvent::Notify(notify_msg) => {
println!("Received notification (new message read): {:?}", notify_msg);
notify_channel.close();
},
}
})?;
Trait Implementations§
Source§impl Clone for WsNotifyChannel
impl Clone for WsNotifyChannel
Source§fn clone(&self) -> WsNotifyChannel
fn clone(&self) -> WsNotifyChannel
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for WsNotifyChannel
impl Debug for WsNotifyChannel
Auto Trait Implementations§
impl Freeze for WsNotifyChannel
impl !RefUnwindSafe for WsNotifyChannel
impl Send for WsNotifyChannel
impl Sync for WsNotifyChannel
impl Unpin for WsNotifyChannel
impl !UnwindSafe for WsNotifyChannel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more