How you explained asynchronous programming in Python is perfect. Not too advanced, and not too simple. Your examples with the times also was great and spot on!
I do have one question about your example when you ping /forgot-passwprd/user9/
, though there is the underutilization of the thread workers in your example for Request 1
-- how can async
help here?
Steps Endpoint resolution
, Email exists in db?
, and Generate token
looks important and I don't think async
would help here as these steps may be more synchronous!
Maybe for Send email
async would work best!
Yes @Flex, for sending email async would definitely work the best. As SMTP network calls typically take seconds.
For checking if email exists in database, This is also a pretty complex IO bound task. CPU is literally waiting for the database drivers to get information. CPUs are super fast and databases are typically 1000s of times slower. So, async can help in database calls too.
Brige the gap between Tutorial hell and Industry. We want to bring in the culture of Clean Code, Test Driven Development.
We know, we might make it hard for you but definitely worth the efforts.
© Copyright 2022-23 Team FastAPITutorial