fork function

Future fork(
  1. Future func(), {
  2. Function? onError,
})

Start a new zone with a new service scope and run func inside it.

The function func must return a Future and the service scope will end when this future completes.

If an uncaught error occurs and onError is given, it will be called. The onError parameter can take the same values as Zone.current.fork.

Implementation

Future fork(Future Function() func, {Function? onError}) {
  var currentServiceScope = _serviceScope;
  currentServiceScope ??= _emptyServiceScope;
  return currentServiceScope._fork(func, onError: onError);
}