mirror of
https://github.com/evennia/evennia.git
synced 2026-03-30 12:37:16 +02:00
Added cmd.funcpart as a way of adding multiple-part commands, each with a possibility to yield with a deferred. This allows for flexible implementation of delayed commands and other asynchronous goodies.
This commit is contained in:
parent
47356ca632
commit
0121f36ac0
2 changed files with 9 additions and 4 deletions
|
|
@ -43,7 +43,7 @@ from src.comms.channelhandler import CHANNELHANDLER
|
|||
from src.utils import logger, utils
|
||||
from src.commands.cmdset import CmdSet
|
||||
from src.commands.cmdparser import at_multimatch_cmd
|
||||
from src.utils.utils import string_suggestions
|
||||
from src.utils.utils import string_suggestions, make_iter
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
|
@ -254,7 +254,7 @@ def cmdhandler(caller, raw_string, testing=False):
|
|||
cmd.raw_string = unformatted_raw_string
|
||||
|
||||
if hasattr(cmd, 'obj') and hasattr(cmd.obj, 'scripts'):
|
||||
# cmd.obj are automatically made available.
|
||||
# cmd.obj is automatically made available.
|
||||
# we make sure to validate its scripts.
|
||||
yield cmd.obj.scripts.validate()
|
||||
|
||||
|
|
@ -270,6 +270,11 @@ def cmdhandler(caller, raw_string, testing=False):
|
|||
# (return value is normally None)
|
||||
ret = yield cmd.func()
|
||||
|
||||
if hasattr(cmd, "funcparts"):
|
||||
# yield on command parts (for multi-part delayed commands)
|
||||
for funcpart in make_iter(cmd.funcparts):
|
||||
yield funcpart()
|
||||
|
||||
# post-command hook
|
||||
yield cmd.at_post_cmd()
|
||||
|
||||
|
|
|
|||
|
|
@ -496,7 +496,7 @@ def uses_database(name="sqlite3"):
|
|||
engine = settings.DATABASE_ENGINE
|
||||
return engine == "django.db.backends.%s" % name
|
||||
|
||||
def delay(to_return, delay=2, callback=None):
|
||||
def delay(delay=2, retval=None, callback=None):
|
||||
"""
|
||||
Delay the return of a value.
|
||||
Inputs:
|
||||
|
|
@ -508,7 +508,7 @@ def delay(to_return, delay=2, callback=None):
|
|||
"""
|
||||
d = defer.Deferred()
|
||||
callb = callback or d.callback
|
||||
reactor.callLater(delay, callb, to_return)
|
||||
reactor.callLater(delay, callb, retval)
|
||||
return d
|
||||
|
||||
_FROM_MODEL_MAP = None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue