Get current request container
Returns the container for the current async context, or undefined if not in request context.
Use Cases:
Request container if in request context, undefined otherwise
Check if currently in request context
Convenience method for conditional logic based on context availability.
true if in request context, false otherwise
Run callback within request context
Container is automatically available to all async operations within the callback, including nested function calls, promises, timers, and queue handlers.
Request-scoped dependency container
Async operation to run with context
Result of callback execution
StaticgetGet singleton instance
Note: Creates instance on first call. Subsequent calls return same instance.
StaticresetInternalReset singleton instance (for testing only)
Warning: Only use in test cleanup. Never call in production code.
Request context store using AsyncLocalStorage
Stores and propagates request container across async operations without manual context passing. This enables transparent access to request-scoped services from any part of the application during request handling.
Cloudflare Workers Compatibility:
nodejs_alscompatibility flag in wrangler.jsoncThread Safety:
Example