import 'dart:async';


main(){

  Future(()=>a1())
      .then((x)=>a2(x))
      .then((x)=>a3(x))
      .then((x)=>a4(x));
//  .whenComplete((x)=>print(x));
  print('done');
}

a1()async{
  await Future.delayed(Duration(seconds: 1));
  print('1');
  return 1;
}

a2(int x)async{
  await Future.delayed(Duration(seconds: 1));
  print('${x+1}');
  return x+1;
}

a3(int x)async{
  await Future.delayed(Duration(seconds: 1));
  print('${x+1}');
  return x+1;
}

a4(int x)async{
  await Future.delayed(Duration(seconds: 1));
  print('${x+1}');
  return x+1;
}

  

 

done
1
2
3
4

Process finished with exit code 0

  

相关文章:

  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2021-06-14
  • 2021-10-29
猜你喜欢
  • 2021-05-19
  • 2022-12-23
  • 2021-07-24
  • 2021-06-05
相关资源
相似解决方案