call method
Processes the given effect in a separate isolate.
effect: The effect to be processed.emit: A function to emit messages back to the main isolate.
This method:
- Creates a ReceivePort to receive messages from the isolate.
- Spawns a new isolate and passes the effect, handle, and a SendPort.
- Listens for messages or the completion signal from the isolate.
Implementation
@override
Future<void> call(Effect effect, MsgEmitter<Msg> emit) async {
final receivePort = ReceivePort();
final isolate = await Isolate.spawn(
_runInIsolate<Effect, Msg>,
_IsolateParams(effect, receivePort.sendPort, handle),
);
await for (final message in receivePort) {
if (message is Msg) {
emit(message);
} else if (message == _doneEvent) {
receivePort.close();
isolate.kill(priority: Isolate.immediate);
break;
}
}
}