The receivePort
is a stream. When you call toList
on the stream, it waits for the stream to complete. That never happens, so the toList
call stalls forever.
If you know that the other end of the communication only sends one message, then you can instead do var d = await receivePort.first;
. This only waits for the first message.
In general, when doing isolate communication, the sending isolate should send a special message when they are done, because the receiving isolate has no other way to know that. That is: You want a communication protocol, so the receiver can know whether there are going to be more messages. Maybe each message is an object which contains an isLast
boolean, or the last message is null
, or you wrap all messages in subclasses of a Message
class that defines your protocol. What to do depends on the actual use-case.
The only rule is: You have to say when you are done.