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
impl ChannelSubscriptionListener
Sourcepub fn new(sender: UnboundedSender<ItemUpdate>) -> Self
pub fn new(sender: UnboundedSender<ItemUpdate>) -> Self
Sourcepub fn create_channel() -> (Self, UnboundedReceiver<ItemUpdate>)
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
ChannelSubscriptionListenerinstance - 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
impl SubscriptionListener for ChannelSubscriptionListener
Source§fn on_item_update(&self, update: &ItemUpdate)
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)
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 moreSource§fn on_unsubscription(&mut self)
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 moreSource§fn on_clear_snapshot(&mut self, _item_name: Option<&str>, _item_pos: usize)
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,
)
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,
)
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)
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,
)
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)
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)
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>)
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 moreAuto Trait Implementations§
impl Freeze for ChannelSubscriptionListener
impl RefUnwindSafe for ChannelSubscriptionListener
impl Send for ChannelSubscriptionListener
impl Sync for ChannelSubscriptionListener
impl Unpin for ChannelSubscriptionListener
impl UnsafeUnpin for ChannelSubscriptionListener
impl UnwindSafe for ChannelSubscriptionListener
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