UseRunStorageScope
katanakit-js / useRunStorageScope
Function: useRunStorageScope()
Section titled “Function: useRunStorageScope()”function useRunStorageScope<T>(fn): Promise<T>;Defined in: infrastructure/storage/storage.service.ts:327
Runs fn with request-isolated in-memory storage (SSR).
Use this around a request handler so useSetStorage / useGetStorage
share state within the request but not across requests.
In browser environments, this simply calls fn() directly (no ALS needed).
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
T |
Return type of fn. |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
fn |
() => T | Promise<T> |
The function to run within the storage scope. |
Returns
Section titled “Returns”Promise<T>
The return value of fn.
Example
Section titled “Example”import { useRunStorageScope, useSetStorage, useGetStorage } from "katanakit-js";
export default defineEventHandler((event) => { return useRunStorageScope(() => { useSetStorage("req-id", event.context.id); return useGetStorage("req-id"); });});