registerIsolateLogPort function

void registerIsolateLogPort(
  1. SendPort port, {
  2. String name = defaultIsolateLogPortName,
})

Registers port (LogSpoolReceiver.sendPort) under name so that engine-started isolates (FCM handler, WorkManager) can find it: they cannot be handed a port at spawn. The port is only a "file appeared in the spool" notification; the entries themselves are in the spool (LogSpool), so a missing or dead port loses nothing.

A previous registration under the same name is replaced: after a hot restart, or after the system killed the main isolate but kept the process, it points at the port of an isolate that has already exited. Throws StateError if the name was taken between removal and registration.

final receiver = LogSpoolReceiver(LogSpool(spoolDirectory), logger.asSink());
registerIsolateLogPort(receiver.sendPort);

Implementation

void registerIsolateLogPort(SendPort port, {String name = defaultIsolateLogPortName}) {
  IsolateNameServer.removePortNameMapping(name);
  if (!IsolateNameServer.registerPortWithName(port, name)) {
    throw StateError('Isolate log port name "$name" was registered concurrently');
  }
}