delete method

Future<void> delete()

Delete the subscription from the server.

Implementation

Future<void> delete() async {
  if (isDeleted || !isCreated) {
    return;
  }

  final request = _httpClient.createRequest('/__transmit/unsubscribe', {
    'channel': _channel,
  });

  _hooks?.beforeUnsubscribe(request);

  try {
    final response = await _httpClient.send(request);

    // Dump the response text
    await response.body;

    if (response.statusCode < 200 || response.statusCode >= 300) {
      return;
    }

    _status = SubscriptionStatus.deleted;
    _hooks?.onUnsubscription(_channel);

    // Notify Transmit to remove this subscription from its internal map
    _onDeleted?.call(_channel);

    // Close the stream controller when subscription is deleted
    if (!_messageStreamController.isClosed) {
      _messageStreamController.close();
    }
  } catch (error) {
    // Error handling
  }
}