safeStream<T> static method
Safely executes an async generator with automatic error handling
Stream closure errors cause graceful termination. Other errors are recorded and rethrown.
Implementation
static Stream<T> safeStream<T>(
Stream<T> Function() streamGenerator,
) async* {
try {
await for (var item in streamGenerator()) {
yield item;
}
} catch (error, stackTrace) {
if (isStreamClosureError(error)) {
// Stream was cancelled/closed, exit gracefully
return;
}
// Record and rethrow other errors
NewrelicMobile.instance.recordError(error, stackTrace);
rethrow;
}
}