run<R, P> method
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
@override
Future<R> run<R, P>(FutureOr<R>? Function(P argument) function, P argument,
{Duration? timeout, FutureOr<R> Function()? onTimeout}) {
return singleResultFuture<R>((SendPort port) {
_commandPort.send(list4(_run, function, argument, port));
}, timeout: timeout, onTimeout: onTimeout);
}