async_job library
Cancellation, child jobs and resource cleanup for asynchronous Dart code.
Start with Job, which runs a function called its body and records how
it ended, and JobContext, which the body is given: checkpoints,
children and cleanup. A Job is not a Future itself: await job.done
for its outcome or job.value for what the body returned.
The guides — outcomes, cancellation, time, children, groups, chains, streams, cleanup, observing, errors, testing and building on the core — are on the documentation site: https://docs.yet-another.dev/async_job/
This is the import for code that runs jobs. The protocol for building an
engine of your own on the core — JobBase, JobContextBase and
JobStatus — is in package:async_job/engine.dart.
Classes
- BodyCancelReason
- The body cancelled itself, directly or by letting a child's cancellation escape.
- CancelReason
- Why a job was cancelled, with any data the reason needs.
- ChainCancelReason
- A cancellation forwarded between jobs connected by Job.then, or from a source to a handle of Job.shared.
-
ChildJob<
T> - A job a parent may start: JobContext.run and JobContext.runAll take nothing else.
-
DeferredJob<
T> - A job that starts when it is told to: by hand, through start, or by a parent, through JobContext.run.
-
Done<
T> - The job body completed and returned value.
- Failed
- The job body threw error, or an engine ended the job with it by hand.
-
Job<
T> - A handle to a job: the outcome, the waiting and the cancellation.
- JobContext
- What a job body sees in the core: cancellation, waiting and children.
- JobObserver
- Cross-cutting hooks of a single job: analytics, error reporting, a log.
- ManualCancelReason
- An explicit cancellation: the default reason of Job.cancel.
-
Outcome<
T> - The result of a job: Done, Failed or Cancelled.
- ParentCancelReason
- A cancellation cascaded from the parent job.
- SiblingCancelReason
- A branch of JobContext.runAll was stopped because its group is failing: another branch of the group ended in an error or a cancellation, or the group itself hit an error, such as a job it refused to take as a branch.
- TimeoutCancelReason
-
The job ran out of the time it was given with
timeout.
Enums
- JobErrorAnswer
- What the job does about an error it hands to JobObserver.onError.
Mixins
- JobAnswerer
- An observer that answers for the errors nobody else has: those no outcome carries, and a failure whose outcome nobody observes.
Exceptions / Errors
- Cancelled
- The job was cancelled before or during its run.