scheduleTask<T> method

Future<T> scheduleTask <T>(TaskCallback<T> task, Priority priority, { String debugLabel, Flow flow })

Schedules the given task with the given priority and returns a Future that completes to the task's eventual return value.

The debugLabel and flow are used to report the task to the Timeline, for use when profiling.

Processing model

Tasks will be executed between frames, in priority order, excluding tasks that are skipped by the current schedulingStrategy. Tasks should be short (as in, up to a millisecond), so as to not cause the regular frame callbacks to get delayed.

If an animation is running, including, for instance, a ProgressIndicator indicating that there are pending tasks, then tasks with a priority below Priority.animation won't run (at least, not with the defaultSchedulingStrategy; this can be configured using schedulingStrategy).

Implementation

Future<T> scheduleTask<T>(TaskCallback<T> task, Priority priority, {
  String debugLabel,
  Flow flow,
}) {
  final bool isFirstTask = _taskQueue.isEmpty;
  final _TaskEntry<T> entry = _TaskEntry<T>(
    task,
    priority.value,
    debugLabel,
    flow,
  );
  _taskQueue.add(entry);
  if (isFirstTask && !locked)
    _ensureEventLoopCallback();
  return entry.completer.future;
}