stream<R> static method

Stream<R> stream<R>(
  1. void build(
    1. SelectBuilder<R>
    ), {
  2. bool ordered = false,
  3. bool stopWhen(
    1. R value
    )?,
})

Repeats run and exposes each winning branch result as a stream.

This is useful for event loops where you want XSelect ergonomics but consume outcomes with await for / stream operators.

Behavior:

  • Rebuilds branches on every iteration (via build).
  • Emits one value per select round.
  • Stops when stopWhen returns true for an emitted value, or when the consumer cancels the stream subscription.

Implementation

static Stream<R> stream<R>(
  void Function(SelectBuilder<R>) build, {
  bool ordered = false,
  bool Function(R value)? stopWhen,
}) async* {
  bool running = true;

  while (running) {
    final value = await run<R>(build, ordered: ordered);
    yield value;
    if (stopWhen?.call(value) ?? false) {
      running = false;
      return;
    }
  }
}