doOnFirst method
Invokes onFirst
with the first event emitted by the stream before any events are yielded.
The onFirst
callback can return a Future; the stream waits for this
future to complete before forwarding the first event.
Subsequent events are passed through without invoking onFirst
.
Implementation
Stream<T> doOnFirst(Future<void> Function(T event) onFirst) async* {
var isFirst = true;
await for (final event in this) {
if (isFirst) {
isFirst = false;
await onFirst(event);
}
yield event;
}
}