connect method

Future<bool> connect()

Implementation

Future<bool> connect() async {
  if (_disconnectingFuture != null) {
    await _disconnectingFuture;
  }

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

    try {
      _box = await retry(task: () => Hive.openBox(storeName));
      _connectingFuture = null;
      completer.complete(true);
    } catch (error) {
      _box = null;
      _connectingFuture = null;
      completer.complete(false);
    }
  }

  if (_connectingFuture != null) return _connectingFuture!;

  return _box != null ? true : false;
}