ZonedWork<T> class
A ZonedWork is an operation for executing a computation inside the Zone container with the possibility of externally controlled termination.
/ The recommended way to terminate a ZonedWork is to request a cancellation using a cancellation token.
⚠️ Warning:
The following warnings concern the various consequences of terminating
ZonedWork using the terminate method.
Because ZonedWork runs in a separate zone with its own uncaught errors
handler ZoneSpecification.handleUncaughtError due to limitations of the
Dart SDK, when using such a handler, in some cases, errors from the parent
zone may not leave the parent zone and may lead to the fact that it will be
physically impossible to catch them (and shut down the Zone correctly).
More detailed information can be found here:
Termination is implemented by attempting to stop code execution in various ways (this does not apply to voluntary termination using a cancellation token) and includes the following actions:
- Canceling timers
- Replacing timer handlers with empty callbacks
- Replacing microtasks with empty callbacks
- Replacing registered callbacks that allow
nullreturns with empty callbacks
When using objects created before ZonedWork was created, these objects may
cause memory leaks.
Example: If (inside ZonedWork) subscribe to a broadcast stream created
before the creation of ZonedWork, and then terminate ZonedWork by
calling the terminate method, the subscription will never be canceled.
- Implemented types
-
- Work<
T>
- Work<
Constructors
-
ZonedWork(FutureOr<
T> computation(), {CancellationToken? token}) - Creates an instance of ZonedWork.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
run(
) → Future< T> -
Executes the computation and returns the computation result (or throws the
exception), or throws the CancellationException exception.
override
-
terminate(
{bool force = false}) → void -
Requests to terminate the execution of a computation.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
Static Methods
-
onExit(
FutureOr< void> handler(ZonedWork<Object?> work)) → bool - Adds an onExit handler to the current ZonedWork instance; if the handler has already been added previously or there is no current ZonedWork instance, then throws a StateError exception.
-
withArgument<
T, R> (T argument, FutureOr< R> computation(T arg), {CancellationToken? token}) → ZonedWork<R> - Creates an instance of ZonedWork.