create<T> static method

Work<T> create<T>(
  1. FutureOr<T> computation(), {
  2. CancellationToken? token,
})

Returns an instance of Work depending on the platform (for the native platform it is IsolatedContext, for the web platform it is ZonedContext).

Parameters:

  • computation: A callback that represents a computation.
  • token: Cancellation token used for canceling the execution of computation.

If the token parameter is specified, it can be retrieved in the computation body by calling Task.token.
Token-based cancellation is a very flexible cancellation method, implemented solely based on the cancellation request processing logic.

Implementation

static Work<T> create<T>(
  FutureOr<T> Function() computation, {
  CancellationToken? token,
}) {
  return _createPlatformSpecificWork(computation, token: token);
}