releaseSubscription method
Releases one local handler attached to a WAMP subscription.
The router is only sent an Unsubscribe request after the last local
handler for subscribed.subscriptionId is released.
Implementation
Future<void> releaseSubscription(Subscribed subscribed) async {
final subscriptionId = subscribed.subscriptionId;
final handlers = _subscriptionHandlers[subscriptionId];
if (handlers == null ||
!handlers.any((handler) => identical(handler, subscribed))) {
return;
}
if (handlers.length == 1) {
await unsubscribe(subscriptionId);
return;
}
handlers.removeWhere((handler) => identical(handler, subscribed));
if (identical(subscriptions[subscriptionId], subscribed)) {
subscriptions[subscriptionId] = handlers.first;
}
await subscribed.closeEventStream();
}