onTimeout method
Add a global timeout to the entire selection.
Unlike onDelay, this applies to the entire selection. If no other branch completes within the timeout duration, the timeout branch will fire and all other operations will be canceled.
Parameters:
d
: Duration before timeoutbody
: Function to call on timeout
Example:
// Network request with fallback
final result = await XSelect.run<ApiResponse>((s) => s
..onFuture(primaryApi(), (response) => response)
..onFuture(secondaryApi(), (response) => response)
..onFuture(cacheApi(), (response) => response)
..onTimeout(Duration(seconds: 30), () => ApiResponse.timeout())
);
Implementation
SelectBuilder<R> onTimeout(Duration d, FutureOr<R> Function() body) {
_branches.add((TimerBranch<R>.once(d, body, tag: 'timeout'), null));
return this;
}