Skip to content

Commit

Permalink
Simplify and remove illegal type flags
Browse files Browse the repository at this point in the history
  • Loading branch information
felixdivo committed Jan 27, 2025
1 parent cab9f19 commit 082a584
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions ros2_easy_test/ros2_easy_test/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from time import monotonic, sleep

# Typing
from typing import Any, Dict, List, Mapping, Optional, Tuple, Type, TypeVar, cast
from typing import Any, Dict, List, Mapping, Optional, Tuple, Type, cast

# ROS
from action_msgs.msg import GoalStatus
Expand All @@ -29,9 +29,6 @@
_DEFAULT_TIMEOUT: Optional[float] = 2


AwaitedType = TypeVar("AwaitedType")


class ROS2TestEnvironment(Node):
"""This class provides a way to interact with nodes and assert that events happen or do not.
Expand Down Expand Up @@ -300,11 +297,10 @@ def clear_messages(self, topic: Optional[str] = None) -> None:
self.clear_messages(topic=topic)

else:
# There is not clear() in SimpleQueue
# There is no clear() in SimpleQueue
self.listen_for_messages(topic, time_span=None) # ignore the result

# In Rolling: Future[AwaitedType]
def await_future(self, future: Future, timeout: Optional[float] = 10) -> AwaitedType:
def await_future(self, future: Future, timeout: Optional[float] = 10) -> Any:
"""Waits for the given future to complete.
Args:
Expand All @@ -328,14 +324,10 @@ def unblock(_: Future) -> None:
# This immediately calls the callback if the future is already done
future.add_done_callback(unblock)

# Check future.done() before waiting on the event.
# The callback might have been added after the future is completed,
# resulting in the event never being set.
if not future.done():
if not event.wait(timeout):
# Timed out. remove_pending_request() to free resources
self.remove_pending_request(future)
raise TimeoutError(f"Future did not complete within {timeout} seconds")
if not event.wait(timeout):
# Timed out. remove_pending_request() to free resources
self.remove_pending_request(future)
raise TimeoutError(f"Future did not complete within {timeout} seconds")

# Potential exception is raised here
return future.result()
Expand Down

0 comments on commit 082a584

Please sign in to comment.