Async, Rethrows, and Defer

For what it's worth, @Joe_Groff brought up the idea of an async defer { } block in this pitch: async let and scoped suspension points (2021-06)

This rule would accommodate async let today, and makes space in the language to introduce other features with scoped implicit suspension points. If we were to reconsider allowing defers that suspend, for instance, we could spell those async defer:

func foo() async {
  await setup()
  // `async` signals potential implicit suspension on scope exit
  async defer { await teardown() }
  doStuff()
}
2 Likes