I don't understand how to use the result argument.
result is simply the value that will be returned by asyncio.sleep once the specified time elapses. This is useful if you replace something that returns actual data with sleep(), e.g. for testing purposes, you can immediately specify a return value. For example:
data = await read_from_database()
...
if mocking:
read_from_database = functools.partial(
asyncio.sleep, 0.1, result='no data')
else:
async def read_from_database():
... real implementation ...
When should the loop argument be used?
The loop argument is, as of Python 3.7 deprecated and scheduled for removal. It was useful in Python 3.5 and earlier, when the return value of asyncio.get_event_loop() wasn't guaranteed to be the currently running event loop, but an event loop associated with the thread. Since one can run multiple event loops during the lifetime of a thread, correct code had to propagate an explicit loop everywhere. If you were running in a non-default event loop, you had to specify the loop to asyncio.sleep and most other asyncio functions and constructors. This style is often encountered in old tutorials and is nowadays actively discouraged.