ZonedWork<T> constructor

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

Creates an instance of ZonedWork.

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

ZonedWork(
  FutureOr<T> Function() computation, {
  CancellationToken? token,
})  : _computation = computation,
      _token = token {
  _zone = Zone.root.fork(
      specification: ZoneSpecification(
        createPeriodicTimer: _createPeriodicTimer,
        createTimer: _createTimer,
        handleUncaughtError: _handleUncaughtError,
        registerBinaryCallback: _registerBinaryCallback,
        registerUnaryCallback: _registerUnaryCallback,
        registerCallback: _registerCallback,
        scheduleMicrotask: _scheduleMicrotask,
      ),
      zoneValues: {_key: this});
}