import 'dart:io';
main(List<String> args) {
print('star');
getNetWorktest1();
getNetWorktest1();
getNetWorktest1();
getNetWorktest1();
print('end');
}
// Future<String> getNetworkData1(String arg){
// return Future(() {
// sleep(Duration(seconds: 5));
// return "KSJ耗时操作测试 + $arg";
// }
// );
// }
getNetWorktest1() async{
var res1 = await getNetWorktest2('KSJ + 1核');
print(res1);
var res2 = await getNetWorktest2('KSJ + 2核');
print(res2);
var res3 = await getNetWorktest2('KSJ + 3核');
print(res3);
var res4 = await getNetWorktest2('KSJ + 4核');
print(res4);
}
Future<String> getNetWorktest2(String string){
return Future(() {
sleep(Duration(seconds: 1));
return "KSJ耗时操作测试:$string + ${DateTime.now()}";
}
);
}
// 业务代码里面一般用then、封装的方法一般用awit和async
// 同时创建多个Future是同步进行操作、但是内部处理进行了分发。分发有需,返回结果无序
// Dart就是单线程加循环——但是Flutter肯定是多线程的,注意范围
⚠️:非常规逻辑执行顺序——所有事件第一步执行完再执行所有事件的第二步依次进行
star
end
KSJ耗时操作测试:KSJ + 1核 + 2020-06-07 09:08:23.077671
KSJ耗时操作测试:KSJ + 1核 + 2020-06-07 09:08:24.102546
KSJ耗时操作测试:KSJ + 1核 + 2020-06-07 09:08:25.103046
KSJ耗时操作测试:KSJ + 1核 + 2020-06-07 09:08:26.107350
KSJ耗时操作测试:KSJ + 2核 + 2020-06-07 09:08:27.109310
KSJ耗时操作测试:KSJ + 2核 + 2020-06-07 09:08:28.112557
KSJ耗时操作测试:KSJ + 2核 + 2020-06-07 09:08:29.116323
KSJ耗时操作测试:KSJ + 2核 + 2020-06-07 09:08:30.118994
KSJ耗时操作测试:KSJ + 3核 + 2020-06-07 09:08:31.122430
KSJ耗时操作测试:KSJ + 3核 + 2020-06-07 09:08:32.127697
KSJ耗时操作测试:KSJ + 3核 + 2020-06-07 09:08:33.130581
KSJ耗时操作测试:KSJ + 3核 + 2020-06-07 09:08:34.136342
KSJ耗时操作测试:KSJ + 4核 + 2020-06-07 09:08:35.139277
KSJ耗时操作测试:KSJ + 4核 + 2020-06-07 09:08:36.144755
KSJ耗时操作测试:KSJ + 4核 + 2020-06-07 09:08:37.149125
KSJ耗时操作测试:KSJ + 4核 + 2020-06-07 09:08:38.153450