码迷,mamicode.com
首页 > 其他好文 > 详细

future then

时间:2019-04-09 20:33:15      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:nis   bsp   pre   ati   delay   print   import   finish   port   

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

  

future then

标签:nis   bsp   pre   ati   delay   print   import   finish   port   

原文地址:https://www.cnblogs.com/pythonClub/p/10679203.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!