run method

Future<Either<L, R>?> run({
  1. required P params,
})

Executes the onCall use case action.

This will initially emit a Running state followed either by a RunFailed or RunSuccess.

If successful, then this will return the rightValue of the RunSuccess. Otherwise, this will return the leftValue of the RunFailed.

If the Runner is closed or a new run call has been made while the current instance is still in progress, then this will return null.

Implementation

Future<Either<L, R>?> run({required P params}) async {
  final actionToken = requestNewActionToken();

  await ensureAsync();

  if (isClosed) return null;

  if (distinctEmit(
        actionToken,
        () => Running(actionToken),
      ) ==
      null) {
    return null;
  }

  final result = await onCall(params);

  if (isClosed) return null;

  distinctEmit(
    actionToken,
    () {
      setParamsAndValue(params, result);

      return result.fold(
        (l) => RunFailed(l, actionToken),
        (r) => RunSuccess(r, actionToken),
      );
    },
  );

  return result;
}