美文网首页
25.Dart中Isolate的简单使用

25.Dart中Isolate的简单使用

作者: 凯司机 | 来源:发表于2020-06-07 10:10 被阅读0次

import 'dart:io';

import 'dart:isolate';

main(List<String> args) {

  /**

  * Isolate的理解:并不是多线程

  * 耗时操作不太合适用在前端

  */

  print('star');

  Isolate.spawn(cacl, 100);

  print('end');

}

cacl(int count) {

  var total = 0;

  for (var i = 0; i < 5; i++) {

    // sleep(Duration(seconds: 1));

    // 不能执行sleep代码

    total+= i;

  }

  // sleep(Duration(seconds: 1));

  // 此处执行sleep后面代码不执行

  print(total);

}

相关文章

网友评论

      本文标题:25.Dart中Isolate的简单使用

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