From 5f491ae5b05271b08d7761b93f966364b1a884d2 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Thu, 30 Apr 2009 14:06:52 +0000 Subject: timer.set_handler() svn path=/rpkid/rpki/async.py; revision=2383 --- rpkid/rpki/async.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'rpkid/rpki/async.py') 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, -- cgit v1.2.3