start<O> method

Future<void> start<O>(
  1. O options,
  2. WorkerTask<I, R, U> create(
    1. O
    )
)

Spawns the worker, where create makes the task from options, and completes once the task exists or with what kept it from existing. create must be sendable: a top-level function or a constructor tear-off.

Implementation

Future<void> start<O>(
  O options,
  WorkerTask<I, R, U> Function(O) create,
) async {
  try {
    await Isolate.spawn(
      _main<I, R, U, O>,
      (_events.sendPort, options, create),
      onError: _events.sendPort,
      onExit: _events.sendPort,
      debugName: 'MediaPipe $_name',
    );
  } catch (error, stack) {
    _events.close();
    Error.throwWithStackTrace(error, stack);
  }
  try {
    await _ready.future;
  } catch (_) {
    await _exited.future;
    rethrow;
  }
}