Skip to content

Commit

Permalink
Make at_post_cmd() run after func() also for delayed commands. Resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
Griatch committed Sep 1, 2020
1 parent 29b381f commit 4ba2f44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -70,6 +70,8 @@ without arguments starts a full interactive Python console.
- Make `INLINEFUNC_STACK_MAXSIZE` default visible in `settings_default.py`.
- Change how `ic` finds puppets; non-priveleged users will use `_playable_characters` list as
candidates, Builders+ will use list, local search and only global search if no match found.
- Make `cmd.at_post_cmd()` always run after `cmd.func()`, even when the latter uses delays
with yield.


## Evennia 0.9 (2018-2019)
Expand Down
31 changes: 21 additions & 10 deletions evennia/commands/cmdhandler.py
Expand Up @@ -206,7 +206,7 @@ def _progressive_cmd_run(cmd, generator, response=None):
else:
value = generator.send(response)
except StopIteration:
pass
raise
else:
if isinstance(value, (int, float)):
utils.delay(value, _progressive_cmd_run, cmd, generator)
Expand Down Expand Up @@ -631,20 +631,31 @@ def _run_command(cmd, cmdname, args, raw_cmdname, cmdset, session, account):
ret = cmd.func()
if isinstance(ret, types.GeneratorType):
# cmd.func() is a generator, execute progressively
_progressive_cmd_run(cmd, ret)
in_generator = True
try:
_progressive_cmd_run(cmd, ret)
except StopIteration:
# this means func() has run its course
in_generator = False
yield None
else:
in_generator = False
ret = yield ret

# post-command hook
yield cmd.at_post_cmd()
if not in_generator:
# this will only run if we are out of the generator for this
# cmd, otherwise we would have at_post_cmd run before a delayed
# func() finished

if cmd.save_for_next:
# store a reference to this command, possibly
# accessible by the next command.
caller.ndb.last_cmd = yield copy(cmd)
else:
caller.ndb.last_cmd = None
# post-command hook
yield cmd.at_post_cmd()

if cmd.save_for_next:
# store a reference to this command, possibly
# accessible by the next command.
caller.ndb.last_cmd = yield copy(cmd)
else:
caller.ndb.last_cmd = None

# return result to the deferred
returnValue(ret)
Expand Down

0 comments on commit 4ba2f44

Please sign in to comment.