aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2009-04-30 14:06:52 +0000
committerRob Austein <sra@hactrn.net>2009-04-30 14:06:52 +0000
commit5f491ae5b05271b08d7761b93f966364b1a884d2 (patch)
treee5a11b6a44442e80aa68e70982b71899edba8797
parent742d1609bb1ed14aa84c0bfd5c9a43bb6ef393c7 (diff)
timer.set_handler()
svn path=/rpkid/rpki/async.py; revision=2383
-rw-r--r--rpkid/rpki/async.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/rpkid/rpki/async.py b/rpkid/rpki/async.py
index 9bd467fd..ab1942c1 100644
--- a/rpkid/rpki/async.py
+++ b/rpkid/rpki/async.py
@@ -100,9 +100,20 @@ class timer(object):
return self in self.queue
def expired(self):
- """Handle a timer that has expired. Subclass must define this."""
+ """Handle a timer that has expired. This must either be overriden
+ by a subclass or set dynamically by set_handler().
+ """
raise NotImplementedError
+ def set_handler(self, handler):
+ """Set timer's expiration handler. This is an alternative to
+ subclassing the timer class, and may be easier to use when
+ integrating timers into other classes (eg, the handler can be a
+ bound method to an object in a class representing a network
+ connection).
+ """
+ self.expired = handler
+
@classmethod
def runq(cls):
"""Run the timer queue: for each timer whose call time has passed,