close method

Future<void> close()

Flushes out the queue for up to timeout seconds and disable the Hub.

Implementation

Future<void> close() async {
  if (!_isEnabled) {
    _options.logger(
      SentryLevel.warning,
      "Instance is disabled and this 'close' call is a no-op.",
    );
  } else {
    // close integrations
    for (final integration in _options.integrations) {
      final close = integration.close();
      if (close is Future) {
        await close;
      }
    }

    final item = _peek();

    try {
      item.client.close();
    } catch (exception, stackTrace) {
      _options.logger(
        SentryLevel.error,
        'Error while closing the Hub',
        exception: exception,
        stackTrace: stackTrace,
      );
    }

    _isEnabled = false;
  }
}