Updated Scheduling Functions (markdown)

Lonami 2019-07-31 13:11:20 +02:00
parent e6f7e52d98
commit 04f2431660

@ -4,25 +4,25 @@ For example, if you want to run `foo` after 10 minutes:
```python
async def foo():
print('hi')
print('hi')
def foo_cb():
client.loop.create_task(foo())
client.loop.create_task(foo())
client.loop.call_later(10 * 60, foo_cb)
```
[`loop.call_later()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.call_later) can only schedule synchronous functions (`call_cb`), but you can use `create_task` to spawn a background, asynchronous task.
[`loop.call_later()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.call_later) can only schedule synchronous functions (`foo_cb`), but you can use `create_task` to spawn a background, asynchronous task.
You can also run something "every N seconds". For example, to repeat `foo` every 10 minutes:
```python
async def foo():
print('hi')
print('hi')
def foo_cb():
client.loop.create_task(foo())
client.loop.call_later(10 * 60, foo_cb)
client.loop.create_task(foo())
client.loop.call_later(10 * 60, foo_cb)
foo_cb()
```
@ -33,9 +33,9 @@ You can also use `while` loops:
```python
async def foo():
while True:
print('hi')
await sleep(10 * 60)
while True:
print('hi')
await sleep(10 * 60)
client.loop.create_task(foo())
```