disconnect method

Future<bool> disconnect()

Implementation

Future<bool> disconnect() async {
  if (_disconnectingFuture == null) {
    final completer = Completer<bool>();
    _disconnectingFuture = completer.future;

    if (_connectingFuture != null) {
      await _connectingFuture;
    }

    try {
      if (_boxFuture != null) {
        await _boxFuture;
      }

      if (_box != null) {
        await _box!.close();
      }

      completer.complete(true);
    } catch (error) {
      completer.complete(false);
    } finally {
      _boxFuture = null;
      _box = null;
    }
  }

  return _disconnectingFuture!;
}