You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
567 B
Markdown
23 lines
567 B
Markdown
# Real Python AsyncIO Walkthrough
|
|
|
|
https://realpython.com/async-io-python/
|
|
|
|
## Rules of Async Coroutines
|
|
|
|
```python
|
|
async def f(x):
|
|
y = await z(x) # OK - `await` and `return` allowed in coroutines
|
|
return y
|
|
|
|
async def g(x):
|
|
yield x # OK - this is an async generator
|
|
|
|
async def m(x):
|
|
yield from gen(x) # No - SyntaxError
|
|
|
|
def m(x):
|
|
y = await z(x) # Still no - SyntaxError (no `async def` here)
|
|
return y
|
|
```
|
|
|
|
An awaitable object is either (1) another coroutine or (2) an object defining an .__await__() dunder method that returns an iterator. |