From 603b4d8ea381f971a840ce099741786ebcaa3b2a Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 18 Jul 2018 13:32:13 -0700 Subject: 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. --- alot/ui.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'alot/ui.py') diff --git a/alot/ui.py b/alot/ui.py index cf7574f0..f8fb7ecc 100644 --- a/alot/ui.py +++ b/alot/ui.py @@ -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): """ -- cgit v1.2.3