Docs: refine async vs def clarification for I/O-bound work

This commit is contained in:
Sai Mahesh sandeboina 2026-01-15 15:02:08 -05:00
parent 61379dcf80
commit 43e8a1a619
1 changed files with 2 additions and 1 deletions

View File

@ -351,7 +351,8 @@ async def read_burgers():
**Clarification on `async def` usage**
Using `async def` is beneficial only when the function performs asynchronous I/O operations, such as awaiting database calls, HTTP requests, or other non-blocking tasks. If a path operation function contains only blocking or CPU-bound code, defining it with `async def` does not provide performance benefits and may add unnecessary complexity. In those cases, using a regular `def` function is recommended.
Using `async def` is beneficial primarily when the function performs I/O-bound work, such as awaiting network or disk operations (e.g. database calls, HTTP requests, or other non-blocking tasks). If a path operation function contains only blocking or CPU-bound code, defining it with `async def` does not provide performance benefits and may add unnecessary complexity. In such cases, using a regular `def` function is often simpler and clearer.
### More technical details { #more-technical-details }