await using (Symbol.asyncDispose) Playground

Mrs. Sari closes the warung with await using: the stove, lamp and radio switch off by themselves, but in what order? What if the food burns, or the stove jams…

Why it matters

Database connections, files, locks, event subscriptions: all must be closed, errors included. try/finally makes it easy to forget one, and the closing order is often wrong. await using (and AsyncDisposableStack) makes async cleanup run by itself, in order, and awaited.

The key idea

Disposed of in reverse, on every way out, and awaited

Common mistakes

Try it in this playground