Class ObservedWait
The toolkit's one polling wait: re-observes a read-only source until it matches, for state that announces its change nowhere the runner can wait on (an adapter's readiness flag, a client's global keys, a synced config value). When the change announces itself, wait for that instead: LogWait for a log line, StateWait for a ValheimCLI game state.
Each round observes once, then fails at once when fails names a reason (WaitFailedException),
returns when matches holds, and otherwise waits at most interval (less when the deadline is nearer) before
observing again. The timeout is required and finite; expiry throws WaitTimeoutException with
describe of the last observation. The cancellation token ends the wait at once, including during the pause.
observe must be read-only: never put a gameplay action in it.
public static class ObservedWait
- Inheritance
-
objectObservedWait
Methods
UntilAsync<T>(string, Func<T>, Func<T, bool>, TimeSpan, TimeSpan, CancellationToken, Func<T, string?>?, Func<T, string>?, Func<TimeSpan, CancellationToken, Task>?)
Waits, without blocking a thread, until observe matches; see ObservedWait. With
changed, each pause ends early when the event it awaits completes, for example a log line the
change produces, through a LogWait opened before the change. It gets the pause's length and a token
cancelled at its end; its expiry or failure only ends the pause, so a missed or absent event costs one interval.
public static Task<T> UntilAsync<T>(string target, Func<T> observe, Func<T, bool> matches, TimeSpan timeout, TimeSpan interval, CancellationToken cancellation = default, Func<T, string?>? fails = null, Func<T, string>? describe = null, Func<TimeSpan, CancellationToken, Task>? changed = null)
Parameters
targetstringobserveFunc<T>matchesFunc<T, bool>timeoutTimeSpanintervalTimeSpancancellationCancellationTokenfailsFunc<T, string>describeFunc<T, string>changedFunc<TimeSpan, CancellationToken, Task>
Returns
- Task<T>
Type Parameters
T
Until<T>(string, Func<T>, Func<T, bool>, TimeSpan, TimeSpan, CancellationToken, Func<T, string?>?, Func<T, string>?)
Blocks until observe matches, observing on the calling thread; see ObservedWait.
public static T Until<T>(string target, Func<T> observe, Func<T, bool> matches, TimeSpan timeout, TimeSpan interval, CancellationToken cancellation = default, Func<T, string?>? fails = null, Func<T, string>? describe = null)
Parameters
targetstringobserveFunc<T>matchesFunc<T, bool>timeoutTimeSpanintervalTimeSpancancellationCancellationTokenfailsFunc<T, string>describeFunc<T, string>
Returns
- T
Type Parameters
T