mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-28 06:53:42 +08:00
new AsyncDisposableStack() compiles to a native stack handle with use, adopt, defer, move, disposeAsync, disposed and [Symbol.asyncDispose], and works with `await using`. disposeAsync runs the resources in reverse order and awaits each result as Node does: the next resource runs one microtask turn after the result settles, a callback that throws is not awaited, and use() of null or undefined costs one await at the end when nothing else was awaited. Failures chain into a SuppressedError, and an invalid receiver rejects the returned promise. use() of a class instance calls its [Symbol.asyncDispose] method, or its [Symbol.dispose] method when it has no async one. The stack lives in a new runtime unit, scr_async_disposable.c, linked when a program uses both symbols and checked-dynamic promises; it shares DisposableStack's storage through scr_disposable.h. Library mode refuses it with the rest of the checked-dynamic async surface.