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
| Attribute | Type | Description |
|---|---|---|
| app | ASGIApp | This 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_name | str = "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
| Name | Type | Description |
|---|---|---|
| app | ASGIApp | The ASGI application. |
| context_name | str = fastapi_middleware_astack | The name to use for the AsyncExitStack in the scope. |