stream<R> static method
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
stopWhenreturnstruefor 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;
}
}
}