dart-lang / dart-lang/language
await for ... on ... catch syntax
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
There is currently no way that I am aware of to handle stream errors in `await for` loops without breaking the loop.
```dart
/// This works, but any error will break the loop and close the subscription
try {
await for (var e in service.probeEvents()) {
status = status.copyWith(probes: e);
yield status;
}
} on StreamException {
///
} catch (e) {
///
}
```
I am proposing that we add syntax on `await for` as an added feature.
```dart
/// Proposing this syntax, where errors will not break the loop
await for (var e in service.probeEvents()) {
status = status.copyWith(probes: e);
yield status;
} on StreamException {
///
} catch (e) {
///
} finally {
/// onDone
}
```
Contributor guide
Research direction
Start by reviewing the issue's proposed await-for syntax and the existing error-handling behavior it describes. The issue names no files or tests; done would require a language-design decision on whether the syntax and its stream-error semantics should be adopted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100