execute method

  1. @override
void execute(
  1. BuildContext context,
  2. WidgetRef ref,
  3. Iterable<GuardBase> guards,
  4. GuardedWidgetUpdate update,
  5. int runId,
  6. int currentRunId(),
)
override

Implementation

@override
void execute(
  BuildContext context,
  WidgetRef ref,
  Iterable<GuardBase> guards,
  GuardedWidgetUpdate update,
  int runId,
  int Function() currentRunId,
) async {
  bool checkIsSync = true;
  for (final guard in guards) {
    // if we has async guards and new check started just return without result
    if (!checkIsSync && currentRunId() != runId) return;
    final rawResult = guard.check(context, ref);
    final guardIsSync = rawResult is! Future;
    final result = guardIsSync ? rawResult : await rawResult;
    checkIsSync &= guardIsSync;

    if (result is GuardCheckResultPass) continue;
    return update(result, runId: runId, sync: checkIsSync);
  }
  return update(
    const GuardCheckResultPass(),
    runId: runId,
    sync: checkIsSync,
  );
}