Created
October 4, 2023 11:59
-
-
Save notpushkin/cfa23e4ab8a73ef9505e2b6e6b2dca5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fastapi import FastAPI, Depends | |
from contextlib import asynccontextmanager, contextmanager | |
app = FastAPI() | |
@contextmanager | |
def get_answer(): | |
yield 42 | |
print("cleanup get_answer") | |
@asynccontextmanager | |
async def get_async_answer(): | |
yield 43 | |
print("cleanup get_async_answer") | |
@app.get("/") | |
def route_get_answer( | |
answer: int = Depends(get_answer), | |
async_answer: int = Depends(get_async_answer), | |
): | |
return { | |
"answer": answer, | |
"async_answer": async_answer, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment