child<T> method

  1. @override
  2. @useResult
ChildJob<T> child<T>(
  1. Future<T> body(
    1. JobContext ctx
    ), {
  2. Object? key,
  3. String describe()?,
  4. Duration? timeout,
})
override

Makes an unstarted child that the engine of this job accepts, for run, start and runAll.

The way to make a child for code that holds a context and does not know the engine behind it: a Job.deferred would do for the core, and an engine that owns its children, solo for one, turns it away.

final rows = await ctx.run(ctx.child(load, key: 'rows', timeout: limit));

Starts nothing and checks nothing, so it never throws for the state of this job: run, start and runAll do the refusing, as they do for any child. timeout is that of Job.deferred: counted from the start of the child's body, and zero or negative throws ArgumentError from here.

The context that makes the child chooses its rules; the job that starts it, most often the same one, becomes its parent, which waits for it, passes it its cancellation and its observer. Until it starts, the child belongs to whoever holds it: no job waits for it or cancels it, its deadline does not run, its done does not complete, and it holds body and all it captured, so cancel one that will not start.

In JobContextBase it is a Job.deferred, a child of the core, whose context knows nothing of an engine's rules. An engine with a context or rules in check of its own, or children it owns, overrides it; each takes its child from there as well.

See Running a child on the children page.

Implementation

@override
@useResult
ChildJob<T> child<T>(
  Future<T> Function(JobContext ctx) body, {
  Object? key,
  String Function()? describe,
  Duration? timeout,
}) => Job.deferred<T>(body, key: key, describe: describe, timeout: timeout);