diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2018-07-18 13:32:13 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2018-07-26 10:36:16 -0700 |
commit | 603b4d8ea381f971a840ce099741786ebcaa3b2a (patch) | |
tree | 03beca863e89e1badf5aaf1edf6b8de352a397ec | |
parent | 781d0a824d5c08277ac73093a4846bd4f6dd2ff6 (diff) |
ui: switch ui.prompt and ui.choice to use asyncio.Futures
asyncio's Futures are much like twisted's Deferreds, they represent a
value that is not yet available, and they can be awaited like a
coroutine.
For the moment we still need to return a deferred because the twisted
eventloop doesn't use Futures, it uses Deferreds; once we can remove
twisted's eventloop we can remove the conversion from a Future to a
deferred.
-rw-r--r-- | alot/ui.py | 12 | ||||
-rw-r--r-- | tests/commands/utils_tests.py | 3 |
2 files changed, 7 insertions, 8 deletions
@@ -327,7 +327,7 @@ class UI(object): """ history = history or [] - d = defer.Deferred() # create return deferred + fut = asyncio.Future() oldroot = self.mainloop.widget def select_or_cancel(text): @@ -335,7 +335,7 @@ class UI(object): with the given text.""" self.mainloop.widget = oldroot self._passall = False - d.callback(text) + fut.set_result(text) def cerror(e): logging.error(e) @@ -371,7 +371,7 @@ class UI(object): None) self.mainloop.widget = overlay self._passall = True - return d # return deferred + return defer.Deferred.fromFuture(fut) @staticmethod def exit(): @@ -556,7 +556,7 @@ class UI(object): assert cancel is None or cancel in choices.values() assert msg_position in ['left', 'above'] - d = defer.Deferred() # create return deferred + fut = asyncio.Future() # Create a returned future oldroot = self.mainloop.widget def select_or_cancel(text): @@ -564,7 +564,7 @@ class UI(object): with the given text.""" self.mainloop.widget = oldroot self._passall = False - d.callback(text) + fut.set_result(text) # set up widgets msgpart = urwid.Text(message) @@ -593,7 +593,7 @@ class UI(object): None) self.mainloop.widget = overlay self._passall = True - return d # return deferred + return defer.Deferred.fromFuture(fut) def notify(self, message, priority='normal', timeout=0, block=False): """ diff --git a/tests/commands/utils_tests.py b/tests/commands/utils_tests.py index f88244a5..cfa8a8dc 100644 --- a/tests/commands/utils_tests.py +++ b/tests/commands/utils_tests.py @@ -21,7 +21,6 @@ import shutil import gpg import mock from twisted.trial import unittest -from twisted.internet.defer import inlineCallbacks from alot import crypto from alot import errors @@ -110,7 +109,7 @@ class TestGetKeys(unittest.TestCase): FPR, validate=True, encrypt=True, signed_only=False) ui = utilities.make_ui() - # Creat a ui.choice object that can satisfy twisted, but can also be + # Creat a ui.choice object that can satisfy asyncio, but can also be # queried for calls as a mock async def choice(*args, **kwargs): return None |