IssueSubscriptionFailures method

Future<void> IssueSubscriptionFailures(
  1. GetStreamingEventsResponse gseResponse
)
Issues the subscription failures. The GetStreamingEvents response.

Implementation

/* private */
Future<void> IssueSubscriptionFailures(
  GetStreamingEventsResponse gseResponse,
) async {
  ServiceResponseException exception = ServiceResponseException(gseResponse);

  for (String? id in gseResponse.ErrorSubscriptionIds) {
    StreamingSubscription? subscription;

    await _lockObject.synchronized(() {
      // Client can do any good or bad things in the below event handler
      if (id != null && _subscriptions.containsKey(id)) {
        subscription = _subscriptions[id];
      }
    });

    if (subscription != null) {
      SubscriptionErrorEventArgs eventArgs = SubscriptionErrorEventArgs(
        subscription,
        exception,
      );

      for (final delegate in OnSubscriptionError) {
        delegate(this, eventArgs);
      }
    }

    if (gseResponse.ErrorCode != ServiceError.ErrorMissedNotificationEvents) {
      // Client can do any good or bad things in the above event handler
      await _lockObject.synchronized(() {
        if (_subscriptions.containsKey(id)) {
          // We are no longer servicing the subscription.
          _subscriptions.remove(id);
        }
      });
    }
  }
}