Skip to the content

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 AsyncLocalStorage or AsyncContext from async-browser-context. The playground cannot import other modules.
  • Use log() to write to the console of the debugger. sleep(ms), fetchUser(id) and save(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 frameno valuescurrentF1requestId = "r-1"F2requestId = "r-2"
root frame
requestId = "r-1"
requestId = "r-2"
Step 1 of 25
Step

Line 3

  • The statement starts in the root frame.
Console
  1. 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 example setTimeout, use the clock of the browser.
  • The debugger shows the frames of run(). It does not show the internal functions of the library.

async-browser-context: AsyncLocalStorage and the TC39 AsyncContext API for browsers. The source code is on GitHub.

To change a page, edit its file in site/content/. The writing style guide tells you how.

An AI model (Claude, from Anthropic) wrote most of the text and the code of this site and of the library, under the direction of the author. The tests and the STE linter examine them.