Clarify declaring function async (#293)

The import and decorator syntax was Python 3.4, with Python 3.5 this
became much nicer and the async keyword is now used.

Use awaited instead of yielded, which makes it easier to read.
This commit is contained in:
Frederik Gladhorn 2019-07-17 15:20:15 +02:00 committed by Martin Hjelmare
parent b18c87ad62
commit 21b7202f1f

View File

@ -10,9 +10,9 @@ Home Assistant uses the convention that all functions that must be run from with
Coroutines are special functions based on Pythons generators syntax which allows them to suspend execution while waiting on a result.
Invoking a coroutine function will return a Generator object back, but will not actually begin execution. This object will execute the task when it is either yielded from (from within another coroutine) or it is scheduled on the event loop.
Invoking a coroutine function will return a Generator object back, but will not actually begin execution. This object will execute the task when it is either awaited (from within another coroutine) or it is scheduled on the event loop.
To declare a function a coroutine, import the coroutine annotation from the asyncio package and annotate your function.
To declare a function a coroutine, add `async` before the `def` of the function definition.
```python
async def async_look_my_coroutine(target):