Playground
Write your own async code and start it with the library. The context debugger shows each step, the frames and each read.
Use the playground
Write code in the editor, then select "Run the code". The page compiles the code in your browser with the Babel preset of the library, the same preset as in an application. Then it starts the code with the real library and shows each step in the context debugger.
- Import
AsyncLocalStorageorAsyncContextfromasync-browser-context. The playground cannot import other modules. - Use
log()to write to the console of the debugger.sleep(ms),fetchUser(id)andsave(value)wait without a server. - Select "Copy a link" to get a link that contains your code.
Press Ctrl + Enter to start the code. The Tab key indents: press Esc and then Tab to move out of the editor. The code can use log(), sleep(ms), fetchUser(id) and save(value) without an import.
playground.jsroot frame
import { AsyncLocalStorage } from "async-browser-context"; const requestId = new AsyncLocalStorage(); async function handle(id, user) { await requestId.run(id, async () => { log(`[${requestId.getStore()}] load ${user}`); const name = await fetchUser(user); log(`[${requestId.getStore()}] hello, ${name}`); await save(name); });} async function save(name) { await sleep(5); log(`[${requestId.getStore()}] saved ${name}`);} await Promise.all([ handle("r-1", "ada"), handle("r-2", "grace"),]); ReadsNo read at this step
FramesArrows point to the parent
root frame
requestId = "r-1"
requestId = "r-2"
Step 1 of 25
Step
Line 3
- The statement starts in the root frame.
Console
- No output yet.
Limits of the playground
- The code can make at most 4,000 steps, and it must end in 5 seconds. After the run, the playground stops the code that still operates.
sleep()uses a clock that the page controls, so each run gives the same steps. Real timers, for examplesetTimeout, use the clock of the browser.- The debugger shows the frames of
run(). It does not show the internal functions of the library.