processLatestOperation<T> method

Future<T?> processLatestOperation<T>(
  1. Future<T> action()
)

Executes the latest operation and returns its result. Only the results of the most recent operation are returned, discarding any previous ongoing operations.

Implementation

Future<T?> processLatestOperation<T>(Future<T> Function() action) async {
  final newOperation = CancelableOperation<T>.fromFuture(action());
  await _currentOperation?.cancel();
  _currentOperation = newOperation;

  return _currentOperation?.value as Future<T>?;
}