run<R> method

Future<R> run<R>(
  1. FutureOr<R> computation()
)

Runs computation in a worker isolate and returns its result. Same rules as Isolate.run for computation (it must be sendable) and its result.

Implementation

Future<R> run<R>(FutureOr<R> Function() computation) {
  if (_closed) {
    return Future.error(StateError("Closed `APIIsolatePool`: $debugName"));
  }

  final job = _PoolJob<R>(computation);
  _queue.add(job);
  _dispatch();
  return job.completer.future;
}