get method

  1. @override
FutureOr<Rx<Operation>?> get({
  1. OperationId? id,
  2. OperationNum? num,
})
override

Returns an Operation identified by the provided id or num.

Implementation

@override
FutureOr<Rx<Operation>?> get({OperationId? id, OperationNum? num}) {
  Log.debug('get($id: id, num: $num)', '$runtimeType');

  final Rx<Operation>? operation = operations.items[id];
  if (operation != null) {
    return operation;
  }

  final identifier = _OperationIdentifier(id: id, num: num);

  // If [operation] doesn't exist, we should lock the [mutex] to avoid remote
  // double invoking.
  Mutex? mutex = _locks[identifier];
  if (mutex == null) {
    mutex = Mutex();
    _locks[identifier] = mutex;
  }

  return mutex.protect(() async {
    Rx<Operation>? operation = operations.items[id];

    if (operation == null) {
      final response = await _graphQlProvider.operation(id, num);
      if (response != null) {
        final DtoOperation dto = response.node.toDto(cursor: response.cursor);

        final rxOperation = operations.items[dto.id] = Rx(dto.value);
        operations.put(dto);

        return rxOperation;
      }
    }

    return operation;
  });
}