future then

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

  

转载于:https://www.cnblogs.com/pythonClub/p/10679203.html

你可能感兴趣的:(future then)