diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2018-08-02 10:23:04 -0700 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2018-08-02 20:33:47 +0100 |
commit | 4ca7f9ffce68d737642071f5dffaa78a738d8520 (patch) | |
tree | 20e60b4358be9857497e6ce873fa9baa3ab9d01b /alot/commands/globals.py | |
parent | ceaad927ca0e4509abea0c02d7af02b6406b55dd (diff) |
commands/globals: Convert CallCommand.apply to a coroutine
This allows it to easily wrap calls that are themselves coroutines,
while it's still able to wrap synchronous calls. This fixes the async
test and allows hooks that are coroutines to work.
Diffstat (limited to 'alot/commands/globals.py')
-rw-r--r-- | alot/commands/globals.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py index f99e5f31..224b671b 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -396,7 +396,7 @@ class CallCommand(Command): Command.__init__(self, **kwargs) self.command = command - def apply(self, ui): + async def apply(self, ui): try: hooks = settings.hooks if hooks: @@ -405,7 +405,9 @@ class CallCommand(Command): if k not in hooks.__dict__: hooks.__dict__[k] = v - exec(self.command) + t = eval(self.command) + if asyncio.iscoroutine(t): + await t except Exception as e: logging.exception(e) msg = 'an error occurred during execution of "%s":\n%s' |