updatePhase method
Moves the work to next and applies the policy's request, if any.
Entering AgentWorkPhase.working or AgentWorkPhase.waiting from a finished phase starts a new run and forgets the reader's toggle. A pause for the reader within a run does not.
Implementation
void updatePhase(AgentWorkPhase next) {
final previous = _phase;
if (next == previous) return;
_phase = next;
if (!next.isFinished && previous.isFinished) {
_readerToggled = false;
}
final request = policy.request(previous, next);
if (request == null || (policy.respectReaderToggle && _readerToggled)) {
return;
}
_request(request, fromLifecycle: true);
}