Skip to content

Commit 3faff2a

Browse files
committed
Add an asyncexecutor decorator
1 parent 04a2cc5 commit 3faff2a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

core/decorators.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import functools
22
import discord
33
from discord.ext import commands
4+
import asyncio
45

56
def trigger_typing(func):
67
@functools.wraps(func)
@@ -26,4 +27,14 @@ def owner_only():
2627
async def predicate(ctx):
2728
allowed = [int(x) for x in str(ctx.bot.config.get('owners', '0')).split(',')]
2829
return ctx.author.id in allowed
29-
return commands.check(predicate)
30+
return commands.check(predicate)
31+
32+
def asyncexecutor(loop=None, executor=None):
33+
loop = loop or asyncio.get_event_loop()
34+
def decorator(func):
35+
@functools.wraps(func)
36+
def wrapper(*args, **kwargs):
37+
partial = functools.partial(func, *args, **kwargs)
38+
return loop.run_in_executor(executor, partial)
39+
return wrapper
40+
return decorator

0 commit comments

Comments
 (0)