| OLD | NEW |
| (Empty) | |
| 1 Scheduler API |
| 2 ============= |
| 3 |
| 4 ```dart |
| 5 typedef void TimerCallback(); |
| 6 |
| 7 class TaskSettings { |
| 8 const TaskSettings({ |
| 9 this.idle: false, // tasks that should run during the idle phase |
| 10 this.layout: false, // tasks that should run during the layout phase |
| 11 this.paint: false, // tasks that should run during the paint phase |
| 12 this.touch: false, // tasks that should run while a pointer is down |
| 13 }); |
| 14 final bool idle; |
| 15 final bool layout; |
| 16 final bool paint; |
| 17 final bool touch; |
| 18 } |
| 19 |
| 20 const idleTask = const TaskSettings(idle: true); |
| 21 const t0 = null; |
| 22 const t1ms = const Duration(milliseconds: 1.0); |
| 23 |
| 24 // Priorities |
| 25 // (these are intentionally not constants, so you can tweak them at runtime) |
| 26 int IdlePriority = 0; // tasks that can be delayed arbitrarily |
| 27 int FutureLayoutPriority = 1000; // tasks that prepare layout |
| 28 int TimerAnimationPriority = 3000; // tasks related to animations |
| 29 int InputPriority = 4000; // input events |
| 30 int InputAnimationPriority = 5000; // framework-fired events for scrolling |
| 31 |
| 32 class Task { |
| 33 external Task(callback, { |
| 34 Duration delay: t0, // how long to wait before scheduling this task; null me
ans run it now (same as duration 0) |
| 35 Duration budget: t1ms, // how long to allow the task to run before firing an
exception; null means no timeout |
| 36 TaskSettings settings: idleTask, // what phases to allow the task to run dur
ing |
| 37 int priority: 0, // the greater the number, the more likely it is to run |
| 38 bool defer: false // punts this task until the next loop (after we're done w
ith paint) |
| 39 }); |
| 40 external void cancel(); // prevents the task from running, if it hasn't run ye
t |
| 41 external bool get active; // true until fired or until canceled |
| 42 } |
| 43 |
| 44 // The Dart native mechanisms for scheduling tasks, as listed below, |
| 45 // get configured as follows: |
| 46 // |
| 47 // delay: duration argument for the Timer constructors, otherwise null (0) |
| 48 // budget: 1ms |
| 49 // settings: same as for the task that triggered this task |
| 50 // priority: same as for the task that triggered this task |
| 51 // defer: false |
| 52 // |
| 53 // method: scheduleMicrotask(Function void callback()) |
| 54 // constructor: Future.microtask(...) // calls scheduleMicrotask() to do the wor
k |
| 55 // constructor: Timer (Duration duration, Function void callback()) |
| 56 // constructor: Timer.periodic(Duration duration, Function void callback(Timer t
imer)) |
| 57 ``` |
| OLD | NEW |