onMessage method

  1. @override
Future<void> onMessage(
  1. dynamic message
)

Handle incoming messages with command/event routing

Implementation

@override
Future<void> onMessage(dynamic message) async {
  // Capture sender keyed by command ID for response routing
  String? commandKey;
  if (message is Command && _isInActorSystem()) {
    final sender = context.sender;
    if (sender != null) {
      commandKey = message.commandId;
      _capturedSenders[commandKey] = sender;
    }
  }

  try {
    await super.onMessage(message);
  } finally {
    if (commandKey != null) {
      _capturedSenders.remove(commandKey);
    }
  }
}