withFallback<T> function
Returns a stream that emits the events from the given stream, or the fallback element if the stream is empty.
Implementation
Stream<T> withFallback<T>(
final Stream<T> stream,
final T fallbackElement,
) async* {
var isEmpty = true;
await for (final event in stream) {
isEmpty = false;
yield event;
}
if (isEmpty) {
yield fallbackElement;
}
}