createAndStart<Q, R> static method

Future<R?> createAndStart<Q, R>(
  1. ComputeCallback<Q, R> callback,
  2. Q message, {
  3. String? debugLabel,
})

Create and start an isolate.

Return the value returned by callback.

Run callback on that isolate, passing it message, and (eventually) return the value returned by callback.

The callback argument must be a top-level function, not a closure or an instance or static method of a class.

Q is the type of the message that kicks off the computation.

R is the type of the value returned.

The debugLabel argument can be specified to provide a name to add to the Timeline. This is useful when in debuggers and logging.

Implementation

static Future<R?> createAndStart<Q, R>(
    ComputeCallback<Q, R> callback, Q message,
    {String? debugLabel}) async {
  final _isolateFlutter =
      await IsolateFlutter.create(callback, message, debugLabel: debugLabel);
  if (_isolateFlutter != null) {
    return _isolateFlutter.start();
  } else {
    return null;
  }
}