Skip to content

Commit

Permalink
address comments about on_process_exit.py
Browse files Browse the repository at this point in the history
  • Loading branch information
wjwwood committed Jun 13, 2018
1 parent 10d8b8b commit 47e498b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions launch/launch/event_handlers/on_process_exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,24 @@ def __init__(self, *, target_action=None, on_exit) -> None: # noqa: F811
# the correct signature for a handler in this case
self.__on_exit = on_exit
self.__actions_on_exit: List[LaunchDescriptionEntity] = []
if isinstance(on_exit, LaunchDescriptionEntity):
self.__on_exit = lambda event, context: on_exit
if callable(on_exit):
# Then on_exit is a function or lambda, so we can just call it, but
# we don't put anything in self.__actions_on_exit because we cannot
# know what the function will return.
pass
else:
# Otherwise, setup self.__actions_on_exit
if isinstance(on_exit, collections.Iterable):
self.__actions_on_exit = on_exit
for entity in on_exit:
if not isinstance(entity, LaunchDescriptionEntity):
raise ValueError(
"expected all items in 'on_exit' iterable to be of type "
"'LaunchDescriptionEntity' but got '{}'".format(type(entity)))
self.__actions_on_exit = list(on_exit) # Outside list is to ensure type is List
else:
self.__actions_on_exit = [on_exit]
# Then return it from a lambda and use that as the self.__on_exit callback.
self.__on_exit = lambda event, context: self.__actions_on_exit

def handle(self, event: Event, context: LaunchContext) -> Optional[SomeActionsType]:
"""Handle the given event."""
Expand Down

0 comments on commit 47e498b

Please sign in to comment.