Dart by Example: Microtasks

  1. import 'dart:async';
  2. main() {
  3. // Future() schedules a task on the event queue:
  4. new Future(() => print('world'));
  5. print('hello');
  6. // scheduleMicrotask() will add the task to the microtask queue:
  7. // Tasks on the microtask queue are executed before the next
  8. // run-loop on the event queue.
  9. scheduleMicrotask(() => print('beautiful'));
  10. print('there');
  11. }
  12.  
  1. $ dart microtasks.dart
  2. hello
  3. there
  4. beautiful
  5. world

by @jryanio | source | license