subscribe method
Operation method that adds a Subscription to the list of "active" Subscriptions. The Subscription cannot already be in the "active" state.
Active subscriptions are subscribed to through the server as soon as possible (i.e. as soon as there is a session available). Active Subscription are automatically persisted across different sessions as long as a related unsubscribe call is not issued.
Lifecycle Subscriptions can be given to the LightstreamerClient at any time. Once done the Subscription
immediately enters the "active" state.
Once "active", a Subscription instance cannot be provided again to a LightstreamerClient unless it is
first removed from the "active" state through a call to unsubscribe.
Also note that forwarding of the subscription to the server is made in a separate thread.
A successful subscription to the server will be notified through a SubscriptionListener.onSubscription
event.
-
sub
A Subscription object, carrying all the information needed to process real-time values. -
See unsubscribe
⚠ WARNING ⚠ The completion of the returned Future indicates that the operation has been accepted and is in progress, but not necessarily completed. To receive notifications about events generated by the operation, it is necessary to register a SubscriptionListener.
Implementation
Future<void> subscribe(Subscription sub) async {
var arguments = <String, dynamic>{
'subscription': sub._toMap()
};
sub._active = true;
await NativeBridge.instance.client_subscribe(_id, sub._id, sub, arguments);
// NB _remoteActive is set after the remote call to ensure that, when the call returns,
// the remote image of the local subscription has been created
sub._remoteActive = true;
//
cleanResources(); // no need to await here
}