我是飞镖的新手,我正在尝试使用隔离运行多种算法以更有效地多次运行它们,但是,当使用 Isolate.spawn 调用多个函数时,我开始在控制台中收到“格式错误的消息”,它仍然有效,但我想知道为什么我会收到此消息,也欢迎任何改进代码的帮助,因为我仍在学习使用隔离的复杂性
stressTest()
{
ReceivePort rpDouble = new ReceivePort();
ReceivePort rpString = new ReceivePort();
ReceivePort rpInteger = new ReceivePort();
int counter = 0;
int tempoTotal = 0;
rpDouble.listen((data) {
counter++;
tempoTotal += data; //data is a stopwatch.toMilliseconds
setState(() { //updating the "progress" and the time it took to run the algorithm in the ui
test = counter.toString() + '%';
_counter = tempoTotal.toString();
});
});
rpInteger.listen((data){
counter++;
tempoTotal += data;
setState(() {
test = counter.toString() + '%';
_counter = tempoTotal.toString();
});
});
rpString.listen((data){
counter++;
tempoTotal += data;
setState(() {
test = counter.toString() + '%';
_counter = tempoTotal.toString();
});
});
for(int i = 0; i < 5; i++) {
Isolate.spawn(DoubleTest, rpDouble.sendPort);
Isolate.spawn(StringStress, rpString.sendPort);
Isolate.spawn(integerTest, rpInteger.sendPort);
}
}
}
DoubleTest、StringStress 和 IntegerTest 是向 sendPort 返回一个 stopwatch.toMilliseconds 整数的函数。
在此先感谢,任何帮助表示赞赏