IsolateTask class
Isolate线程管理工具类
使用示例:
// 1. 定义isolate入口函数
void isolateFunction(List<dynamic> args) {
SendPort sendPort = args[0];
dynamic message = args[1];
// 在这里处理耗时任务
var result = heavyComputation(message);
// 发送结果回主isolate
sendPort.send(result);
}
// 2. 在主isolate中使用
void main() async {
// 启动新的isolate
await IsolateManager.spawn('worker', isolateFunction, data);
// 检查isolate是否存在
if(IsolateManager.exists('worker')) {
print('Worker isolate is running');
}
// 完成后终止isolate
IsolateManager.kill('worker');
// 或终止所有isolate
IsolateManager.killAll();
}
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- activeCount → int
-
获取活跃的isolate数量
no setter