disconnect method

Future<bool> disconnect()

Implementation

Future<bool> disconnect() async {
  if (_connectingFuture != null) {
    await _connectingFuture;
  }

  if (_box != null && _disconnectingFuture == null) {
    final completer = Completer<bool>();
    _disconnectingFuture = completer.future;

    try {
      await _box!.close();
      _box = null;
      _disconnectingFuture = null;
      completer.complete(true);
    } catch (error) {
      _box = null;
      _disconnectingFuture = null;
      completer.complete(false);
    }
  }

  if (_disconnectingFuture != null) {
    return _disconnectingFuture!;
  }

  return _box == null ? true : false;
}