【发布时间】:2022-04-27 10:31:09
【问题描述】:
我正在尝试从 Isolate 函数调用异步函数。
class IsolateExample {
final ReceivePort port = new ReceivePort();
IsolateExample(){
Isolate.spawn(isolateFunction, port.sendPort);
}
static isolateFunction(SendPort port){
print('inside isolateFunction');
asyncFunction();
}
static void asyncFunction() async {
print('inside asyncFunction');
}
}
上述类的用法:
final IsolateExample _isolate = new IsolateExample();
上面的代码看起来很简单,但 asyncFunction 永远不会被调用。我不知道为什么会失败。
【问题讨论】:
-
我已经简化了上面的内容。在实际代码中,我需要随着时间的推移返回多个值。我猜 compute() 不支持多次返回。
-
否,compute 仅支持单个同步返回值。支持单个异步返回值存在一个未解决的问题。
-
嗯,到目前为止,该样本没有问题。我可以看到
print('inside asyncFunction')
标签: flutter dart dart-isolates