summaryrefslogtreecommitdiff
path: root/src/core/core.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-08-01 01:22:59 +0200
committerFlorent Le Coz <louiz@louiz.org>2014-08-01 01:22:59 +0200
commit87cf38995a283e4a476fd124fcc55e0f80edf1ad (patch)
tree54e434be6a56ae5d501d4c2e769dd7ca1cbb4009 /src/core/core.py
parent55daf9d49df4a0e0774b27acd33735abf80f80dd (diff)
downloadpoezio-87cf38995a283e4a476fd124fcc55e0f80edf1ad.tar.gz
poezio-87cf38995a283e4a476fd124fcc55e0f80edf1ad.tar.bz2
poezio-87cf38995a283e4a476fd124fcc55e0f80edf1ad.tar.xz
poezio-87cf38995a283e4a476fd124fcc55e0f80edf1ad.zip
Make the TimedEvents work with asyncio
Improvements: events now occur precisely at the specified date. You don’t need to stop touching your keyboard to execute them.
Diffstat (limited to 'src/core/core.py')
-rw-r--r--src/core/core.py22
1 files changed, 4 insertions, 18 deletions
diff --git a/src/core/core.py b/src/core/core.py
index 446cc9f0..b2951aea 100644
--- a/src/core/core.py
+++ b/src/core/core.py
@@ -262,8 +262,6 @@ class Core(object):
self.initial_joins = []
- self.timed_events = set()
-
self.connected_events = {}
self.pending_invites = {}
@@ -749,22 +747,13 @@ class Core(object):
def remove_timed_event(self, event):
"""Remove an existing timed event"""
- if event and event in self.timed_events:
- self.timed_events.remove(event)
+ event.handler.cancel()
def add_timed_event(self, event):
"""Add a new timed event"""
- self.timed_events.add(event)
-
- def check_timed_events(self):
- """Check for the execution of timed events"""
- now = datetime.now()
- for event in self.timed_events:
- if event.has_timed_out(now):
- res = event()
- if not res:
- self.timed_events.remove(event)
- break
+ event.handler = asyncio.get_event_loop().call_later(event.delay,
+ event.callback,
+ *event.args)
####################### XMPP-related actions ##################################
@@ -1628,9 +1617,6 @@ class Core(object):
a non-None value), but we check for timed events instead.
"""
res = self.keyboard.get_user_input(self.stdscr)
- while res is None:
- self.check_timed_events()
- res = self.keyboard.get_user_input(self.stdscr)
return res
def escape_next_key(self):