deferred<T> static method

DeferredJob<T> deferred<T>(
  1. Future<T> body(
    1. JobContext ctx
    ), {
  2. Object? key,
  3. String describe()?,
  4. bool cancellable = true,
  5. Duration? timeout,
  6. JobObserver? observer,
})

Creates a job that waits to be told to start.

The result is a DeferredJob, and whoever owns it starts it: by hand through DeferredJob.start, or a parent through JobContext.run or JobContext.runAll. Cancelled before that, it ends Cancelled with started: false, and its body never runs.

The named parameters are those of Job.new. The deadline of timeout is counted from the start, so the time the job waits for it is not counted; and a child with a deadline is how one step of a body gets one: await ctx.run(ctx.child(step, key: 'step', timeout: limit)) throws the child's Cancelled(timeout) into the body of the parent, which catches it or lets it out. JobContext.child makes the child the engine of the body accepts; in the core that is this one.

Implementation

static DeferredJob<T> deferred<T>(
  Future<T> Function(JobContext ctx) body, {
  Object? key,
  String Function()? describe,
  bool cancellable = true,
  Duration? timeout,
  JobObserver? observer,
}) => _DeferredJob<T>(
  body,
  key: key,
  describe: describe,
  cancellable: cancellable,
  timeout: timeout,
  observer: observer,
);