mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-31 07:23:06 +08:00
An async generator whose body suspends only at its own awaits and yields now compiles to an LLVM switched coroutine, as async functions of that kind already do, instead of running on a fiber with its own stack. Its steps run on the stack that resumes it (the loop's after an await), its awaits suspend through scr_coro_await_prepare and scr_coro_hop_prepare, and its yields store OUT through scr_coro_yield_* before suspending. - scr_async_gen_new_stackless creates the generator. The stackless hop settles an async generator's state as the fiber hop does, and a step that would start below the stack guard throws a RangeError, which rejects its request. - Calling an async generator's next, return or throw no longer counts as parking the caller: they queue a request and run the body to its next suspension, which returns to the caller. Bodies that consume async generators can now be stackless too. - An untyped await (async.awaitDyn) has a native coroutine form, extracted by scr_coro_await_dyn_value, so async bodies that await untyped values can be stackless. - An async generator's return through a finally region takes its await turn through the coroutine when the body is one. Debug builds, libraries, worker programs and Windows executables keep fibers, as for stackless async functions.