From 8b582c9d3f8d6daa38261c43f0a2f5732c1d56b1 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 14 Oct 2012 11:54:26 +0200 Subject: [PATCH] Added a delay() function to src.utils.utils, useful for simple delays without needing a script. --- src/utils/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/utils/utils.py b/src/utils/utils.py index 4fff530a84..fe0dd186f2 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -496,6 +496,20 @@ def uses_database(name="sqlite3"): engine = settings.DATABASE_ENGINE return engine == "django.db.backends.%s" % name +def delay(to_return, delay=2, callback=None): + """ + Delay the return of a value. + Inputs: + to_return (any) - this will be returned by this function after a delay + delay (int) - the delay in seconds + callback (func(r)) - if given, this will be called with the to_return after delay seconds + Returns: + deferred that will fire with to_return after delay seconds + """ + d = defer.Deferred() + callb = callback or d.callback + reactor.callLater(delay, callb, to_return) + return d _FROM_MODEL_MAP = None _TO_DBOBJ = lambda o: (hasattr(o, "dbobj") and o.dbobj) or o