这是我的代码。我查看了Future.delayed & Future的源代码。Future和Future.delayed都执行Time.run。Future Duration 是Duration.zero,但 Future.delayed(Duration(microseconds:n(ps:n<1000)),fun) 更快,有趣的是当 n >= 1000 时它会反转。
void event(){
print("Future delayed start");
Future.delayed(Duration(microseconds:999), (){
print("Future delayed end");
}).then((value) => {
print("Future.delayed.then")
}).whenComplete(() => {
print("Future.delayed.whenComplete")
});
print("Future start");
Future((){
print("Future end");
}).then((value) => {
print("Future.then")
}).whenComplete(() => {
print("Future.whenComplete")
});
}
这是输出。
flutter: Future delayed start
flutter: Future start
flutter: Future delayed end
flutter: Future.delayed.then
flutter: Future.delayed.whenComplete
flutter: Future end
flutter: Future.then
flutter: Future.whenComplete
提前致谢。