Skip to content

UseRunStorageScope

katanakit-js / 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 Parameter Description
T Return type of fn.
Parameter Type Description
fn () => T | Promise<T> The function to run within the storage scope.

Promise<T>

The return value of fn.

import { useRunStorageScope, useSetStorage, useGetStorage } from "katanakit-js";
export default defineEventHandler((event) => {
return useRunStorageScope(() => {
useSetStorage("req-id", event.context.id);
return useGetStorage("req-id");
});
});