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

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();
            },
        }
    })?;

Close the WebSocket notification channel.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more