start method

Future<void> start(
  1. int isolates,
  2. Future<Server> spawn(
    1. SendPort?
    )
)

Implementation

Future<void> start(
  int isolates,
  Future<Server> Function(SendPort?) spawn,
) async {
  if (isRunning) {
    // TODO(isolate): update error message.
    throw StateError('Server is already running.');
  }

  try {
    for (var isolate = 0; isolate < isolates; isolate += 1) {
      var supervisor =
          await IsolateSupervisor.spawn(this, spawn, isolate + 1);
      supervisors.add(supervisor);
      await supervisor.resume();
    }

    for (var isolate = 0; isolate < isolates; isolate += 1) {
      supervisors[isolate].sendPendingMessages();
    }

    isRunning = true;
  } catch (error) {
    await close();
  }
}