JobContext class abstract interface

What a job body sees in the core: cancellation, waiting and children.

Once the job has accepted a cancellation, the members that wait or start something throw that Cancelled: check, abandonable, join, pause, uncancellable, onCancel, run, runAll and each. The members that only register do not — onDispose, onDiscard, disown and unattended go on working, so a body that has just been cancelled can still put what it holds on the cleanup stack, and still hand out a stop nobody waits for — and neither do child, log, job and heldCancellation: child only makes a child, and the members that start one are the ones that refuse. What a cancellation arriving during a call does to that call is the call's own business: see abandonable, join, pause and uncancellable.

A context that outlived its job — captured by a closure nobody awaited — neither waits nor starts nor registers anything: every member throws a StateError once the job has finished, except check, child, log, job and heldCancellation. While the core unwinds the cleanup stack the same holds for the members that wait or start something, and for check on a job that is not cancelled — but child, onDispose, onDiscard, disown and unattended go on working, because a value arriving that late is put on the stack the core is unwinding, and a disposer may hand out work nobody waits for.

Implementers

Properties

hashCode → int
The hash code for this object.
no setterinherited
heldCancellation → Cancelled?
The cancellation an open uncancellable section of this job is holding back, or null.
no setter
job → Job<Object?>
The job this context belongs to.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

abandonable<T>(FutureOr<T> action(), {FutureOr<void> dispose(T value)?, FutureOr<void> discard(T value)?}) → Future<T>
Runs action and waits for it, but no longer than this job lives.
check() → void
Gives up if the job was cancelled, or if a rule its engine adds stopped holding.
child<T>(Future<T> body(JobContext ctx), {Object? key, String describe()?, Duration? timeout}) → ChildJob<T>
Makes an unstarted child that the engine of this job accepts, for run, start and runAll.
disown(Object value) → bool
Drops the cleanup registered for value by abandonable, join or run.
each<T>(Stream<T> stream, FutureOr<void> onData(JobContext ctx, T event), {Object? key, String describe()?}) → Job<void>
Starts a child job that processes stream one event at a time.
join<T>(FutureOr<T> action(), {FutureOr<void> dispose(T value)?, FutureOr<void> discard(T value)?}) → Future<T>
Runs action, waits for all of it, and gives up only afterwards.
log(Object? message) → void
Hands message to JobObserver.onLog as it is.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onCancel(void callback()) → void Function()
Registers callback to run the moment the job accepts a cancellation, before the body itself learns about it.
onDiscard(FutureOr<void> disposer()) → void Function()
Registers disposer to run unless the job ends Done: when it is cancelled, or fails.
onDispose(FutureOr<void> disposer()) → void Function()
Registers disposer to run when the job ends, whatever the outcome.
pause([Duration duration = Duration.zero]) → Future<void>
Waits for duration, or until the job is cancelled.
run<T>(ChildJob<T> child, {FutureOr<void> dispose(T value)?, FutureOr<void> discard(T value)?}) → Future<T>
Starts child right now, as a child of this job, ahead of whatever an engine would have put it through.
runAll<T>(Iterable<ChildJob<T>> children) → Future<List<T>>
Runs children side by side and stops the rest as soon as one of them goes wrong.
start(ChildJob<Object?> child) → void
Starts child right now, as a child of this job, and leaves its outcome to whoever holds it.
toString() → String
A string representation of this object.
inherited
unattended(FutureOr<void> action()) → void
Runs action as work this job does not wait for.
uncancellable<T>(FutureOr<T> action()) → Future<T>
Runs action with the cancellation held back, and waits for it.

Operators

operator ==(Object other) → bool
The equality operator.
inherited