Created
March 15, 2019 08:26
-
-
Save dotdoom/6c205539e875136ab7533c3bd24e1e7f to your computer and use it in GitHub Desktop.
Future, async and scheduleMicrotask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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