aboutsummaryrefslogtreecommitdiffstats
path: root/bot/utils/scheduling.py
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2018-10-06 21:22:21 +0000
committerGravatar Leon Sandøy <[email protected]>2018-10-06 21:22:21 +0000
commita9b280e819de555a3f52d0e0f37da002122eae93 (patch)
tree4442cf1f0f88faa1b13d40413ce6242c5ca673ac /bot/utils/scheduling.py
parentMerge branch 'better-moderation' into 'master' (diff)
parentAdd Reminders cog. (diff)
Merge branch 'remind-command' into 'master'
Add Reminders cog. See merge request python-discord/projects/bot!55
Diffstat (limited to '')
-rw-r--r--bot/utils/scheduling.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/bot/utils/scheduling.py b/bot/utils/scheduling.py
new file mode 100644
index 000000000..f9b844046
--- /dev/null
+++ b/bot/utils/scheduling.py
@@ -0,0 +1,22 @@
+import asyncio
+import contextlib
+
+
+def create_task(loop: asyncio.AbstractEventLoop, coro_or_future):
+ """
+ Creates an asyncio.Task object from a coroutine or future object.
+
+ :param loop: the asyncio event loop.
+ :param coro_or_future: the coroutine or future object to be scheduled.
+ """
+
+ task: asyncio.Task = asyncio.ensure_future(coro_or_future, loop=loop)
+
+ # Silently ignore exceptions in a callback (handles the CancelledError nonsense)
+ task.add_done_callback(_silent_exception)
+ return task
+
+
+def _silent_exception(future):
+ with contextlib.suppress(Exception):
+ future.exception()