Skip to content

Instantly share code, notes, and snippets.

@dotdoom
Created March 15, 2019 08:26
Show Gist options
  • Save dotdoom/6c205539e875136ab7533c3bd24e1e7f to your computer and use it in GitHub Desktop.
Save dotdoom/6c205539e875136ab7533c3bd24e1e7f to your computer and use it in GitHub Desktop.
Future, async and scheduleMicrotask
import 'dart:async';
Future<void> b(value) async {
await Future.delayed(Duration(seconds: 0));
// OR: remove the line ABOVE for fun effect.
print('b(${value})');
}
Future<void> a(value) async {
print('a(${value})');
scheduleMicrotask(() => b(value));
// OR: replace scheduleMicrotask() with await b(value);
return value + 1;
}
void main() {
scheduleMicrotask(() => print('microtask1'));
a(1).then(a).then(a);
print('done');
scheduleMicrotask(() => print('microtask2'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment