handleEventLoopCallback method Null safety

  1. @visibleForTesting
bool handleEventLoopCallback()
visibleForTesting">@visibleForTesting

Execute the highest-priority task, if it is of a high enough priority.

Returns true if a task was executed and there are other tasks remaining (even if they are not high-enough priority).

Returns false if no task was executed, which can occur if there are no tasks scheduled, if the scheduler is locked, or if the highest-priority task is of too low a priority given the current schedulingStrategy.

Also returns false if there are no tasks remaining.

Implementation

@visibleForTesting
@pragma('vm:notify-debugger-on-exception')
bool handleEventLoopCallback() {
  if (_taskQueue.isEmpty || locked) {
    return false;
  }
  final _TaskEntry<dynamic> entry = _taskQueue.first;
  if (schedulingStrategy(priority: entry.priority, scheduler: this)) {
    try {
      _taskQueue.removeFirst();
      entry.run();
    } catch (exception, exceptionStack) {
      StackTrace? callbackStack;
      assert(() {
        callbackStack = entry.debugStack;
        return true;
      }());
      FlutterError.reportError(FlutterErrorDetails(
        exception: exception,
        stack: exceptionStack,
        library: 'scheduler library',
        context: ErrorDescription('during a task callback'),
        informationCollector: (callbackStack == null) ? null : () {
          return <DiagnosticsNode>[
            DiagnosticsStackTrace(
              '\nThis exception was thrown in the context of a scheduler callback. '
              'When the scheduler callback was _registered_ (as opposed to when the '
              'exception was thrown), this was the stack',
              callbackStack,
            ),
          ];
        },
      ));
    }
    return _taskQueue.isNotEmpty;
  }
  return false;
}