engine runs in an event loop. When a blocking operation is needed, the request is started, and the code keeps running without blocking for the result. When the response is ready, an interrupt is fired, which causes an event handler to be run, where the control flow continues. In this way, a single program thread can handle many concurrent operations.
queue - Attendant takes 2 minute to sell fuel and 1 minute to collect payment - Attendant takes a total of 3 minute to attend to each customer - In 1 hour 20 people would be attended to - For 500 people the attendant would take 25 hours
queue - Attendant takes 2 minute to sell fuel - Attendant moves to attend to the next customer while the previous customer gets the cash ready and hands over the cash to the attendant while selling for the next customer - Attendant takes a total of 3 minute to attend to each customer - In 1 hour 30 people would be attended to - For 500 people the attendant would around 16.6 hours
single-threaded concurrent code using coroutines, multiplexing I/O access over sockets and other resources, running network clients and servers, and other related primitives.
so we don’t need to worry about multithreading (GIL Issue, context switching, race conditions, resource starvation) - It runs code concurrently (It’s a form of programming which means doing many things at once) - It takes advantage of the system resources
library in python 3.5 + - Makes it more clear that your code is asynchronous (easier to think about than threads) - Better than callback and promises - The async keyword goes before def to show that a method is asynchronous. - The await keyword replaces yield from and makes it more clear that you are waiting for a coroutine to finish.