Removed func_parts looping from cmdhandler - it didn't work as expected, as shown in #438. Instead reworked utils.delay() to implement the same functionality explicitly.
This commit is contained in:
parent
393a3e5e73
commit
6ea4125ef1
2 changed files with 10 additions and 16 deletions
|
|
@ -399,14 +399,6 @@ def cmdhandler(called_by, raw_string, testing=False, callertype="session", sessi
|
||||||
# (return value is normally None)
|
# (return value is normally None)
|
||||||
ret = yield cmd.func()
|
ret = yield cmd.func()
|
||||||
|
|
||||||
if hasattr(cmd, "func_parts"):
|
|
||||||
# yield on command parts (for multi-part delayed commands)
|
|
||||||
for func_part in make_iter(cmd.func_parts):
|
|
||||||
err = yield func_part()
|
|
||||||
# returning anything but a deferred/None will kill the chain
|
|
||||||
if err:
|
|
||||||
break
|
|
||||||
|
|
||||||
# post-command hook
|
# post-command hook
|
||||||
yield cmd.at_post_cmd()
|
yield cmd.at_post_cmd()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -485,24 +485,26 @@ def uses_database(name="sqlite3"):
|
||||||
return engine == "django.db.backends.%s" % name
|
return engine == "django.db.backends.%s" % name
|
||||||
|
|
||||||
|
|
||||||
def delay(delay=2, retval=None, callback=None):
|
def delay(delay=2, callback=None, retval=None):
|
||||||
"""
|
"""
|
||||||
Delay the return of a value.
|
Delay the return of a value.
|
||||||
Inputs:
|
Inputs:
|
||||||
delay (int) - the delay in seconds
|
delay (int) - the delay in seconds
|
||||||
retval (any) - this will be returned by this function after a delay
|
callback (func() or func(retval)) - if given, will be called without
|
||||||
callback (func(retval)) - if given, this will be called with retval
|
arguments or with retval after delay seconds
|
||||||
after delay seconds
|
retval (any) - this will be returned by this function after a delay,
|
||||||
|
or as input to callback
|
||||||
Returns:
|
Returns:
|
||||||
deferred that will fire with callback after delay seconds. Note that
|
deferred that will fire with callback after delay seconds. Note that
|
||||||
if delay() is used in the commandhandler callback chain, the callback
|
if delay() is used in the commandhandler callback chain, the callback
|
||||||
chain can be defined directly in the command body and don't need to be
|
chain can be defined directly in the command body and don't need to be
|
||||||
specified here.
|
specified here.
|
||||||
"""
|
"""
|
||||||
d = defer.Deferred()
|
callb = callback or defer.Deferred().callback
|
||||||
callb = callback or d.callback
|
if retval is not None:
|
||||||
reactor.callLater(delay, callb, retval)
|
return reactor.callLater(delay, callb, retval)
|
||||||
return d
|
else:
|
||||||
|
return reactor.callLater(delay, callb)
|
||||||
|
|
||||||
|
|
||||||
_TYPECLASSMODELS = None
|
_TYPECLASSMODELS = None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue