onFuture<T> method

SelectBuilder<R> onFuture<T>(
  1. Future<T> fut,
  2. FutureOr<R> body(
    1. T
    ), {
  3. Object? tag,
  4. bool if_()?,
})

Race a Future - handles both success and error cases.

The future is automatically canceled if another branch wins the race. Use this when you need to handle both successful completion and errors.

Parameters:

  • fut: Future to race
  • body: Function to call with the future's result
  • tag: Optional tag for debugging
  • if_: Optional guard condition

Example:

await XSelect.run<String>((s) => s
  ..onFuture(apiCall(), (result) => 'API returned: $result')
  ..onFuture(fallbackCall(), (result) => 'Fallback: $result')
  ..onTimeout(Duration(seconds: 5), () => 'timeout')
);

See also:

Implementation

SelectBuilder<R> onFuture<T>(Future<T> fut, FutureOr<R> Function(T) body,
    {Object? tag, bool Function()? if_}) {
  _branches.add((FutureBranch<T, R>(fut, body, tag: tag), if_));
  return this;
}