25.Dart中Isolate的简单使用

2020-06-07  本文已影响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);

}

上一篇 下一篇

猜你喜欢

热点阅读