waitFor method
Implementation
Future waitFor(WorkPhase t,
{Duration? timeout, FutureOr<WorkStatus> onTimeout()?}) async {
try {
if (_status.phase < t) {
log.warning(
'We are still in ${_status.phase} phase - waiting for $t${timeout == null ? '' : ' (timeout ${timeout.inMilliseconds}'}');
final fw = _ctrl.stream.firstWhere((element) => element.phase >= t);
if (timeout == null) {
return fw;
} else if (timeout.inMicroseconds <= 0) {
return fw;
} else {
return fw.timeout(timeout, onTimeout: onTimeout);
}
} else {
log.warning(
'We are at ${_status.phase} phase - good enough to move on to for $t');
return;
}
} on TimeoutException {
log.severe("timed out after $timeout waiting for $t");
rethrow;
}
}