getOrCreateSubscriptionController method
Implementation
StreamController<SubscriptionMessage> getOrCreateSubscriptionController(
String subscription,
[FutureOr<void> Function(String subscription)? onCancel]) {
if (subscriptions.containsKey(subscription)) {
return subscriptions[subscription]!;
} else {
final controller =
StreamController<SubscriptionMessage>.broadcast(onCancel: () async {
if (onCancel != null) {
await onCancel(subscription);
}
if (subscriptions.containsKey(subscription)) {
subscriptions.remove(subscription);
}
});
subscriptions[subscription] = controller;
return controller;
}
}