isolateWorker<R, P> function

  1. @Deprecated('Use `IsolateManagerFunction.workerFunction` instead')
Future<void> isolateWorker<R, P>(
  1. IsolateWorkerFunction<R, P> function, {
  2. FutureOr<void> onInitial()?,
})

Create a worker in your main.

main() {
  isolateWorker(myFunction);
}

Build it with dart compile js worker.dart -o worker.js -O4 and copy the worker.js to your Web folder.

When you're using the onInitial, you have to set the autoInitialize parameter of the create and createCustom to false. Without it, the Worker will be stucked forever.

If you need to throw an exception, you should only throw the message instead of a whole Object because it may not be shown as expected when sending back to the main app.

 return throw 'This is an error that you need to catch in your main app';

Implementation

@Deprecated('Use `IsolateManagerFunction.workerFunction` instead')
Future<void> isolateWorker<R, P>(
  IsolateWorkerFunction<R, P> function, {
  FutureOr<void> Function()? onInitial,
}) {
  return isolateWorkerImpl<R, P>(function, onInitial);
}