call method

  1. @override
Future<void> call(
  1. Effect effect,
  2. MsgEmitter<Msg> emit
)
override

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:

  1. Creates a ReceivePort to receive messages from the isolate.
  2. Spawns a new isolate and passes the effect, handle, and a SendPort.
  3. 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;
    }
  }
}