Examples
Patterns you can copy.
Each example isolates one ownership concern so the lifetime remains visible in ordinary TypeScript.
Owned parallel work
Start independent child tasks while preserving one request boundary.
const user = context.fork("user", (signal) =>
fetchUser(id, { signal })
)
const feed = context.fork("feed", (signal) =>
fetchFeed(id, { signal })
)
return context.json({
user: await user,
feed: await feed,
})
Scoped database resource
Acquire once and guarantee cleanup after the owning scope settles.
const db = await context.use(
"database",
(signal) => connect({ signal }),
(resource) => resource.close(),
)
return context.json(await db.query(...))
Streaming delivery
Keep the file handle alive until the response stream closes.
const file = await context.delivery.use(
"file",
() => openFile(path),
(resource) => resource.close(),
)
return new Response(file.stream())
Need the underlying model?
Read request ownership before building an adapter.
Open the concept guide