Normally, functions will run synchronously. For example, say that you had three different functions within your code, traditionally, your functions will wait until a return true or termination and then execute the next function in the code.
func1()
func2()
func3()
Please note, this is NOT to be confused with multithreading. This is completely different.
Hypothetically, we have three functions and we are waiting on func1()
to finish, however, we do NOT want to waste CPU time, so we decide to execute func2()
. We are NOT running func1() and func2()
simultaneously, but rather putting func1()
to sleep or in a waiting state and use our CPU time on func2()
or func3()
while we wait to be very efficient.
In order to achieve this, we will need to import the asyncio
library.
import asyncio
You want to define a function as asynchronous, rather than the whole program.
To achieve this, you will use the async
keyword:
async def main():
The next step is to sleep this