Skip to main content

AsyncExitStackMiddleware

This class provides an ASGI middleware that manages an asynchronous exit stack for each request. It makes an AsyncExitStack instance available in the ASGI scope, allowing downstream applications to register asynchronous cleanup operations that will be executed when the request finishes.

Attributes

AttributeTypeDescription
appASGIAppThis attribute stores the ASGI application that the middleware will wrap and is used to process incoming requests after the middleware has performed its operations.
context_namestr = "fastapi_middleware_astack"This attribute stores the key under which the AsyncExitStack instance will be stored in the ASGI scope, allowing downstream applications to access and manage asynchronous context.

Constructor

Signature

def AsyncExitStackMiddleware(
app: ASGIApp,
context_name: str = fastapi_middleware_astack
) - > null

Parameters

NameTypeDescription
appASGIAppThe ASGI application.
context_namestr = fastapi_middleware_astackThe name to use for the AsyncExitStack in the scope.