I have a FastAPI endpoints for game state updates. Each user has some guess count and if that becomes 0, then there will be cool down timer for x seconds before guesses can be replenished.
So how should this be supported from the server end? Should server fire an event when a user guess count becomes 0, that it can sleep for cool down time until guesses are replenished. If yes, how can that be done? Is there something FastAPI provides on that?
Yes, you can do that, without code it's hard to provide a exact answer, but you can achieve that by Background Tasks
So it could look something like this:
from fastapi import BackgroundTasks
async def refresh_user_stats(user: User = Depends(get_current_user)):
do something here
@app.update()
async def refresh_user(background_tasks: BackgroundTasks):
background_tasks.add_task(refresh_user_stats())