JobBase<T> class abstract

The lifecycle of a job: start, body, children, cancellation, outcome.

Subclass it to add a domain of your own — the state, the rules and the queue in solo, a scope elsewhere. Everything the engine of that domain needs is protected, and the subclass hands out exactly what it needs through private wrappers of its own: a @protected member is for the subclass alone, and an engine reaches a job from the side.

Implemented types

Constructors

JobBase({Object? key, String describe()?, bool cancellable = true, Duration? timeout, JobObserver? observer})
Creates a job that has not started yet.

Properties

bodyEnded → bool
Whether the body has ended — returned or thrown.
no setter
cancellable → bool
Whether the job accepts a cancellation it may refuse, as it was created.
no setter
children → List<JobBase<Object?>>
The children this job waits for, in the order they were adopted; read-only.
no setter
creationZone → Zone
The zone the job was created in, where an unobserved failure of the job goes when no observer answers for it.
no setter
done → Future<Outcome<T>>
Completes with the outcome; never throws.
no setteroverride
hashCode → int
The hash code for this object.
no setterinherited
heldCancel → Cancelled?
The cancellation an open section is holding back, or null.
no setter
inUncancellableSection → bool
Whether a section opened by enterUncancellable is open right now.
no setter
isCancelled → bool
Whether the job has accepted a cancellation, even if the body still runs, or has ended with one.
no setteroverride
isChild → bool
Whether this job was adopted by a parent — through JobContext.run, JobContext.runAll or JobContext.each.
no setteroverride
isDisposing → bool
Whether the core is unwinding the cleanup stack.
no setter
isFinished → bool
Whether outcome is set.
no setteroverride
isRunning → bool
Whether the body is running or its children are still finishing.
no setteroverride
key → Object?
The key given at creation.
no setteroverride
level → int
Nesting depth: 0 for a root job, parent.level + 1 for a child.
no setteroverride
outcome → Outcome<T>?
The outcome, or null until the job is finished.
no setteroverride
pendingCancel → Cancelled?
The cancellation the job has accepted, or null.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
status → JobStatus
Where the job is in its life.
no setter
untilFinished → Future<void>
Waiting without observing: an engine waits for a job to finish without marking its outcome observed, so a failure nobody looked at is still answered for.
no setter
value → Future<T>
Completes with the returned value, or throws Cancelled with the cancellation stack trace, or throws the body's error.
no setteroverride

Methods

adoptedBy(JobContextBase parent) → void
The child's own word on who may adopt it.
cancel({CancelReason reason = const ManualCancelReason()}) → Future<void>
Cancels the job with reason and waits for it to actually finish.
override
cancelWith(Cancelled cancelled, {bool rejectable = true}) → void
Cancels the job with cancelled, correcting started to its status.
createContext() → JobContextBase
The context this job hands to its body.
describe() → String
The description given at creation, or an empty string.
override
enterUncancellable() → void
Opens an uncancellable section: a rejectable cancellation arriving now is held, and the job accepts it only when the section closes.
execute(JobContextBase ctx) → Future<T>
Runs the body with ctx; a subclass narrows the type with covariant.
finish(Outcome<T> outcome) → void
Ends the job with outcome.
finished() → void
The subclass leaves the run.
ignoreFailure() → void
Tells the core that nobody is interested in this job's failure.
override
leaveUncancellable() → void
Closes a section opened by enterUncancellable and lets a held cancellation through — the outermost section is the one that lands it, and a job that finished meanwhile ignores it as it would any other late cancellation.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyError(Object error, StackTrace stackTrace) → void
Announces error and asks for an answer to it.
notifyObserver(Object error, StackTrace stackTrace) → void
Announces error to the observer and asks nobody to answer for it: the door an engine announces through.
reportToZone(Object error, StackTrace stackTrace) → void
Hands error to the zone the job was created in, unless it is a cancellation.
requireShared(String reason) → void
Refuses then on this job from now on, with reason in the error: every continuation is a handle of shared.
shared({Object? key, String describe()?, JobObserver? observer}) → Job<T>
Creates a handle that finishes with the outcome of this job and cannot reach it: one branch of a job continued in several.
override
start() → void
Runs the body.
started() → void
The subclass joins the run.
then<R>(FutureOr<R> onValue(JobContext ctx, T value), {Object? key, String describe()?, JobObserver? observer}) → Job<R>
Creates a job that runs onValue after this job succeeds and cleans up.
override
toString() → String
Never throws: a key whose toString throws, or a describe that does, is printed as a mark, Job(key: <describe threw StateError>).
override
whenCancelled(void callback(Cancelled)) → void Function()
Registers callback for cancellation and returns an unregister function.
override
whenFinished(void callback(Outcome<T> outcome)) → void Function()
Registers callback for the end of the job and returns an unregister function.
override

Operators

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