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);
}
网友评论