Skip to content

await for ... on ... catch syntax #1441

Open
@lukepighetti

Description

@lukepighetti

There is currently no way that I am aware of to handle stream errors in await for loops without breaking the loop.

/// 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.

/// 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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProposed language feature that solves one or more problems

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions