start method
- @protected
Runs the body.
The job starts in the zone this is called from: its body runs there, and
so do started and the observer's onStart. Called inside the work of
JobContext.unattended, it starts in the zone that work was started
from, past any zone forked inside the work, as a job made in there does:
a job is not that work, and its errors are not the observer's of the job
that started it.
Throws StateError if the job already ran, and also if it was cancelled before it started: a job dropped then is finished, and a finished job does not run. Nor does one ended while createContext built its context, and then this returns without a word: that end was the engine's own.
Implementation
@protected
void start() {
// Inside the work of `JobContext.unattended` the whole start moves out,
// not the body alone: `started` and `onStart` are the job's own too, and
// a hook that throws in the work would report to the observer of the job
// that started it. To the zone the work was started from, the one a job
// made in there reports to. Through `run`, not a microtask: the job
// starts now, as it does anywhere else, and a `StateError` still reaches
// the caller.
final outsideTheWork = Zone.current[_unattendedKey] as Zone?;
if (outsideTheWork == null) {
_start();
} else {
outsideTheWork.run(_start);
}
}