execute method
Executes this StreamQueue in an async loop invoking the provided
onEvent
on every T
event happening.
Implementation
Future<void> execute(
FutureOr<void> Function(T) onEvent, {
FutureOr<void> Function(Object e)? onError,
}) async {
try {
while (await hasNext) {
T? event;
try {
event = await next;
} catch (e) {
await onError?.call(e);
}
if (event != null) {
await onEvent(event);
}
}
} on StateError catch (e) {
if (e.message != 'Already cancelled') {
rethrow;
}
}
}