Skip to main content

ChannelSubscriptionListener

Struct ChannelSubscriptionListener 

Source
pub struct ChannelSubscriptionListener { /* private fields */ }
Expand description

A subscription listener that forwards item updates to a tokio mpsc channel.

This listener allows decoupling the reception of updates from their processing, enabling asynchronous consumption of updates by other tasks or components.

§Examples

use lightstreamer_rs::subscription::{ChannelSubscriptionListener, ItemUpdate};
use tokio::sync::mpsc;

let (tx, mut rx) = mpsc::unbounded_channel();
let listener = ChannelSubscriptionListener::new(tx);

// Add listener to subscription
subscription.add_listener(Box::new(listener));

// Process updates in a separate task
tokio::spawn(async move {
    while let Some(update) = rx.recv().await {
        println!("Received update: {:?}", update);
    }
});

Implementations§

Source§

impl ChannelSubscriptionListener

Source

pub fn new(sender: UnboundedSender<ItemUpdate>) -> Self

Creates a new ChannelSubscriptionListener with the provided sender.

§Arguments
  • sender - An unbounded mpsc sender for forwarding ItemUpdate events
§Returns

A new instance of ChannelSubscriptionListener

Source

pub fn create_channel() -> (Self, UnboundedReceiver<ItemUpdate>)

Creates a new channel pair and returns both the listener and receiver.

This is a convenience method that creates both the channel and the listener in a single call.

§Returns

A tuple containing:

  • The ChannelSubscriptionListener instance
  • The receiver end of the channel for consuming updates
§Examples
use lightstreamer_rs::subscription::ChannelSubscriptionListener;

let (listener, mut rx) = ChannelSubscriptionListener::create_channel();
subscription.add_listener(Box::new(listener));

tokio::spawn(async move {
    while let Some(update) = rx.recv().await {
        // Process update
    }
});

Trait Implementations§

Source§

impl SubscriptionListener for ChannelSubscriptionListener

Source§

fn on_item_update(&self, update: &ItemUpdate)

Event handler that is called by Lightstreamer each time an update pertaining to an item in the Subscription has been received from the Server. Read more
Source§

fn on_subscription(&mut self)

Event handler that is called by Lightstreamer to notify that a Subscription has been successfully subscribed to through the Server. This can happen multiple times in the life of a Subscription instance, in case the Subscription is performed multiple times through LightstreamerClient::unsubscribe() and LightstreamerClient::subscribe(). This can also happen multiple times in case of automatic recovery after a connection restart. Read more
Source§

fn on_unsubscription(&mut self)

Event handler that is called by Lightstreamer to notify that a Subscription has been successfully unsubscribed from. This can happen multiple times in the life of a Subscription instance, in case the Subscription is performed multiple times through LightstreamerClient::unsubscribe() and LightstreamerClient::subscribe(). This can also happen multiple times in case of automatic recovery after a connection restart. Read more
Source§

fn on_clear_snapshot(&mut self, _item_name: Option<&str>, _item_pos: usize)

Event handler that is called by Lightstreamer each time a request to clear the snapshot pertaining to an item in the Subscription has been received from the Server. More precisely, this kind of request can occur in two cases: Read more
Source§

fn on_command_second_level_item_lost_updates( &mut self, _lost_updates: u32, _key: &str, )

Event handler that is called by Lightstreamer to notify that, due to internal resource limitations, Lightstreamer Server dropped one or more updates for an item that was subscribed to as a second-level subscription. Such notifications are sent only if the Subscription was configured in unfiltered mode (second-level items are always in “MERGE” mode and inherit the frequency configuration from the first-level Subscription). Read more
Source§

fn on_command_second_level_subscription_error( &mut self, _code: i32, _message: Option<&str>, _key: &str, )

Event handler that is called when the Server notifies an error on a second-level subscription. Read more
Source§

fn on_end_of_snapshot(&mut self, _item_name: Option<&str>, _item_pos: usize)

Event handler that is called by Lightstreamer to notify that all snapshot events for an item in the Subscription have been received, so that real time events are now going to be received. The received snapshot could be empty. Such notifications are sent only if the items are delivered in DISTINCT or COMMAND subscription mode and snapshot information was indeed requested for the items. By implementing this method it is possible to perform actions which require that all the initial values have been received. Read more
Source§

fn on_item_lost_updates( &mut self, _item_name: Option<&str>, _item_pos: usize, _lost_updates: u32, )

Event handler that is called by Lightstreamer to notify that, due to internal resource limitations, Lightstreamer Server dropped one or more updates for an item in the Subscription. Such notifications are sent only if the items are delivered in an unfiltered mode; this occurs if the subscription mode is: Read more
Source§

fn on_listen_end(&mut self)

Event handler that receives a notification when the SubscriptionListener instance is removed from a Subscription through Subscription::remove_listener(). This is the last event to be fired on the listener.
Source§

fn on_listen_start(&mut self)

Event handler that receives a notification when the SubscriptionListener instance is added to a Subscription through Subscription::add_listener(). This is the first event to be fired on the listener.
Source§

fn on_real_max_frequency(&mut self, _frequency: Option<f64>)

Event handler that is called by Lightstreamer to notify the client with the real maximum update frequency of the Subscription. It is called immediately after the Subscription is established and in response to a requested change (see Subscription::set_requested_max_frequency()). Since the frequency limit is applied on an item basis and a Subscription can involve multiple items, this is actually the maximum frequency among all items. For Subscriptions with two-level behavior (see Subscription::set_command_second_level_fields() and Subscription::set_command_second_level_field_schema()), the reported frequency limit applies to both first-level and second-level items. Read more
Source§

fn on_subscription_error(&mut self, _code: i32, _message: Option<&str>)

Event handler that is called when the Server notifies an error on a Subscription. By implementing this method it is possible to perform recovery actions. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more