test1() {
Future.delayed(Duration(seconds: 2),(){
print(">>>>>>>>test1");
});
}
test2() {
print(">>>>>>>>test2");
}
test(){
test1();
test2();
}
输出结果 test2 test1
test1() async{
await Future.delayed(Duration(seconds: 2),(){
print(">>>>>>>>test1");
});
print(">>>>>>>>test11");
}
test2() {
print(">>>>>>>>test2");
}
test(){
test1();
test2();
}
输出结果 test2 test1 test11也就是说,await阻塞的,是包裹在外面的一层异步函数,这个函数里面后面的代码会被阻塞。
不用await就不是窜行
test1() async{
Future.delayed(Duration(seconds: 2),(){
print(">>>>>>>>test1");
});
print(">>>>>>>>test11");
}
test2() async{
// await Future.delayed(Duration(seconds: 3),(){
print(">>>>>>>>test2");
// });
}
test() async{
test1();
test2();
}
test11 test2 test1