我正在学习Isolate
's。我阅读了文档。并想编写最小的工作示例。这是我的代码:
main() async
{
ReceivePort receivePort = ReceivePort();
Isolate.spawn(echo, receivePort.sendPort);
var sendPort = await receivePort.first;
}
echo(SendPort sendPort)
{
ReceivePort receivePort = ReceivePort();
sendPort.send(receivePort);
}
几乎没问题,但我不明白如何发回简单的“Hello”消息。我看了几个例子,有一些中间件,比如sendReceive()
. 我正确理解之后:
var sendPort = await receivePort.first;
sendPort
将存储生成函数的名称/地址,我需要sendPort.send("hello");
吗?