Diagrams
The parts of the runtime, the steps of the coroutine and the transform pipeline.
The parts of the runtime
Show the diagram source
flowchart TB
subgraph api["Public API"]
variable["AsyncContext.Variable"]
snapshot["AsyncContext.Snapshot"]
als["AsyncLocalStorage"]
end
subgraph runtime["Runtime"]
store["Store: the current frame"]
frames["Frames: one variable and one value each"]
coroutine["coroutine()"]
asyncgen["asyncGenerator()"]
bind["bindGenerator()"]
patches["Patches: then, timers, events, observers, streams"]
end
als --> variable
variable -->|"run() makes"| frames
variable -->|"get() reads"| store
snapshot -->|"records"| store
coroutine -->|"sets for each step"| store
asyncgen -->|"sets for each step"| store
bind -->|"sets for each step"| store
patches -->|"sets for each callback"| store
store --> framesThe steps of the coroutine
Show the diagram source
sequenceDiagram
participant Caller
participant Coroutine as coroutine()
participant Body as Generator body
participant Queue as Microtask queue
Caller->>Coroutine: start the async function
Coroutine->>Body: step 1 in the frame of the function
Body-->>Coroutine: yield (was await)
Coroutine->>Coroutine: set the previous frame
Coroutine->>Queue: native await of the value
Queue->>Coroutine: the value settles
Coroutine->>Body: step 2 in the frame of the function
Body-->>Coroutine: the function is complete
Coroutine->>Coroutine: set the previous frameThe transform pipeline
Show the diagram source
flowchart TB
module["Module (also in node_modules)"] --> plugin["Vite plugin, after the other plugins"]
plugin --> skip["Skip the functions of the runtime"]
skip --> bind["Bind the generators"]
bind --> names["Name the async functions, for the hooks"]
names --> statics["Move static members with async arrows"]
statics --> helpers["Async generator helpers from the runtime"]
helpers --> resources["using and await using"]
resources --> genresources["using in async generators"]
genresources --> asyncgen["Async generators and for await"]
asyncgen --> asyncfn["Async functions with coroutine()"]
asyncfn --> out["Module that imports the runtime"]