run<R, P> method

Future<R> run <R, P>(FutureOr<R> function(P argument), P argument, { Duration timeout, dynamic onTimeout() })
override

Execute function(argument) in the isolate and return the result.

Sends function and argument to the isolate, runs the call, and returns the result, whether it returned a value or threw. If the call returns a Future, the final result of that future will be returned.

This works similar to the arguments to Isolate.spawn, except that it runs in the existing isolate and the return value is returned to the caller.

Example:

IsolateRunner iso = await IsolateRunner.spawn();
try {
  return await iso.run(heavyComputation, argument);
} finally {
  await iso.close();
}

Implementation

Future<R> run<R, P>(FutureOr<R> function(P argument), P argument,
    {Duration timeout, onTimeout()}) {
  return singleResultFuture<R>((SendPort port) {
    _commandPort.send(list4(_RUN, function, argument, port));
  }, timeout: timeout, onTimeout: onTimeout);
}