createWithArgument<T, R> static method

Work<R> createWithArgument<T, R>(
  1. T argument,
  2. FutureOr<R> computation(
    1. T arg
    ), {
  3. 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:

  • argument: Argument to pass to the computation function.
  • computation: A function 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<R> createWithArgument<T, R>(
  T argument,
  FutureOr<R> Function(T arg) computation, {
  CancellationToken? token,
}) {
  return _createPlatformSpecificWork(() => computation(argument),
      token: token);
}