launch method

Future<RoomHandle> launch(
  1. Future<void> entry(
    1. RoomLaunch launch
    ), {
  2. required String roomId,
  3. int port = 0,
})

Implementation

Future<RoomHandle> launch(
  Future<void> Function(RoomLaunch launch) entry, {
  required String roomId,
  int port = 0,
}) async {
  if (_rooms.containsKey(roomId)) {
    throw StateError('room already running ($roomId)');
  }
  final control = ReceivePort();
  final isolate = await Isolate.spawn(_roomMain, (
    entry,
    roomId,
    port,
    control.sendPort,
  ), debugName: 'room-$roomId');
  final boundPort = await control.first as int;
  control.close();
  final handle = RoomHandle._(roomId, boundPort, isolate);
  _rooms[roomId] = handle;
  return handle;
}