From 04f243166031071afe19837559f1d71e74f95e3f Mon Sep 17 00:00:00 2001 From: Lonami Date: Wed, 31 Jul 2019 13:11:20 +0200 Subject: [PATCH] Updated Scheduling Functions (markdown) --- Scheduling-Functions.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Scheduling-Functions.md b/Scheduling-Functions.md index a76b199..e677679 100644 --- a/Scheduling-Functions.md +++ b/Scheduling-Functions.md @@ -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()) ```