mirror of
https://github.com/ArchipelagoMW/Archipelago.git
synced 2026-03-07 15:13:52 -08:00
Core: allow async def functions as commands (#5859)
This commit is contained in:
@@ -1302,6 +1302,13 @@ class CommandMeta(type):
|
||||
commands.update(base.commands)
|
||||
commands.update({command_name[5:]: method for command_name, method in attrs.items() if
|
||||
command_name.startswith("_cmd_")})
|
||||
for command_name, method in commands.items():
|
||||
# wrap async def functions so they run on default asyncio loop
|
||||
if inspect.iscoroutinefunction(method):
|
||||
def _wrapper(self, *args, _method=method, **kwargs):
|
||||
return async_start(_method(self, *args, **kwargs))
|
||||
functools.update_wrapper(_wrapper, method)
|
||||
commands[command_name] = _wrapper
|
||||
return super(CommandMeta, cls).__new__(cls, name, bases, attrs)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user