Future

作者: 苍老师的眼泪 | 来源:发表于2020-10-25 02:27 被阅读0次
    main() {
      //传递给Future构造函数的函数参数会立即开始执行,但是可能非常耗时,但不阻塞接下来的代码执行
      var future = Future(() {
        print('hello world');
      });
    
      print('this run here1');
      //Future.then也不阻塞它后面的代码执行
      future.then((value) => print(value));
      print('this run here2');
    }
    

    实测结果(可能每次都不一样,具体取决于要执行的语句和机器)

    [Running] dart "c:\Users\root\Desktop\flutter\myshop\test.dart"
    this run here1
    this run here2
    hello world
    null
    

    相关文章

      网友评论

          本文标题:Future

          本文链接:https://www.haomeiwen.com/subject/rbummktx.html