Future链式使用
2021-08-20 本文已影响0人
凯司机
import 'dart:io';
main(List<String> args) {
print('start');
Future((){
sleep(Duration(seconds: 3));
return "第1次的结果";
}).then((res){
print(res);
sleep(Duration(seconds: 3));
return "第2次的结果";
}).then((res){
print(res);
sleep(Duration(seconds: 3));
return "第3次的结果";
}).then((res){
print(res);
sleep(Duration(seconds: 3));
return "第4次的结果";
}).then((res){
print(res);
}).catchError((error) {
print("$error");
}).whenComplete((){
print("全部执行结束...");
});
print("end");
}