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

  

posted @ 2019-04-09 19:41  CrossPython  阅读(397)  评论(0)    收藏  举报