From 9c3a9385040d6f8c09858d2aa1f308cd51e66a80 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 3 Mar 2014 20:48:49 +0100 Subject: Sometimes returns the last return MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/util.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/util.py b/src/util.py index 0ed41f8..d9fc5e5 100644 --- a/src/util.py +++ b/src/util.py @@ -113,6 +113,7 @@ class Sometimes: self.function = function self.interval = interval self.counter = initial + self.last_return = None def __call__(self, *args, **kargs): ''' @@ -120,11 +121,12 @@ class Sometimes: @param args:*? The parameters of the function @param kargs:**? The named parameters of the function - @return :¿R?? The return value of the function, `None` if not invoked + @return :¿R? The return value of the function, the last return if not invoked ''' - rc = None + rc = self.last_return if self.counter == 0: rc = self.function(*args, **kargs) + self.last_return = rc self.counter = self.interval self.counter -= 1 return rc -- cgit v1.2.3-70-g09d2