mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-07-10 16:12:22 +03:00
Updated Scheduling Functions (markdown)
parent
e6f7e52d98
commit
04f2431660
|
@ -4,25 +4,25 @@ For example, if you want to run `foo` after 10 minutes:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
async def foo():
|
async def foo():
|
||||||
print('hi')
|
print('hi')
|
||||||
|
|
||||||
def foo_cb():
|
def foo_cb():
|
||||||
client.loop.create_task(foo())
|
client.loop.create_task(foo())
|
||||||
|
|
||||||
client.loop.call_later(10 * 60, foo_cb)
|
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:
|
You can also run something "every N seconds". For example, to repeat `foo` every 10 minutes:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
async def foo():
|
async def foo():
|
||||||
print('hi')
|
print('hi')
|
||||||
|
|
||||||
def foo_cb():
|
def foo_cb():
|
||||||
client.loop.create_task(foo())
|
client.loop.create_task(foo())
|
||||||
client.loop.call_later(10 * 60, foo_cb)
|
client.loop.call_later(10 * 60, foo_cb)
|
||||||
|
|
||||||
foo_cb()
|
foo_cb()
|
||||||
```
|
```
|
||||||
|
@ -33,9 +33,9 @@ You can also use `while` loops:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
async def foo():
|
async def foo():
|
||||||
while True:
|
while True:
|
||||||
print('hi')
|
print('hi')
|
||||||
await sleep(10 * 60)
|
await sleep(10 * 60)
|
||||||
|
|
||||||
client.loop.create_task(foo())
|
client.loop.create_task(foo())
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue
Block a user