start static method

Future<RenderPool> start({
  1. required String bundle,
  2. int warm = 1,
  3. void onGuestLog(
    1. String line
    )?,
})

Implementation

static Future<RenderPool> start({
  required String bundle,
  int warm = 1,
  void Function(String line)? onGuestLog,
}) async {
  var bundleDir = p.absolute(bundle);
  var manifestFile = File(p.join(bundleDir, 'manifest.json'));
  if (!manifestFile.existsSync()) {
    throw StateError(
      'not a render bundle: ${manifestFile.path} does not exist '
      '(produce one with `fw render bundle`)',
    );
  }
  var manifest = RenderBundleManifest.fromJson(
    (jsonDecode(manifestFile.readAsStringSync()) as Map)
        .cast<String, Object?>(),
  );
  if (manifest.protocol != renderProtocolVersion) {
    throw StateError(
      'this client speaks render protocol $renderProtocolVersion but the '
      'bundle was built for ${manifest.protocol}; rebuild the bundle or '
      'upgrade flutterware',
    );
  }
  var pool = RenderPool._(bundleDir, manifest, warm, onGuestLog);
  try {
    await Future.wait([for (var i = 0; i < warm; i++) pool._spawn()]);
  } catch (_) {
    // One spawn failing must not orphan the ones that succeeded: they are
    // --run-forever processes nobody else can reach.
    await pool.close();
    rethrow;
  }
  return pool;
}