-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow adapted feeds to filter messages #123
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,10 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: | |
to the underlying `message_filters.ApproximateTimeSynchronizer`. | ||
""" | ||
super().__init__() | ||
self._unsafe_synchronizer = message_filters.ApproximateTimeSynchronizer(*args, **kwargs) | ||
self._unsafe_synchronizer = message_filters.ApproximateTimeSynchronizer( | ||
*args, | ||
**kwargs, | ||
) | ||
self._unsafe_synchronizer.registerCallback(self.signalMessage) | ||
|
||
def __getattr__(self, name: str) -> Any: | ||
|
@@ -175,7 +178,9 @@ def _wait_callback(self, messages: Sequence[Any], future: Future) -> None: | |
time, | ||
) | ||
self._ongoing_wait_time = time | ||
self._ongoing_wait.add_done_callback(functools.partial(self._wait_callback, messages)) | ||
self._ongoing_wait.add_done_callback( | ||
functools.partial(self._wait_callback, messages), | ||
) | ||
else: | ||
self._ongoing_wait_time = None | ||
self._ongoing_wait = None | ||
|
@@ -204,7 +209,9 @@ def add(self, *messages: Any) -> None: | |
time, | ||
) | ||
self._ongoing_wait_time = time | ||
self._ongoing_wait.add_done_callback(functools.partial(self._wait_callback, messages)) | ||
self._ongoing_wait.add_done_callback( | ||
functools.partial(self._wait_callback, messages), | ||
) | ||
|
||
|
||
class Adapter(Filter): | ||
|
@@ -215,15 +222,19 @@ def __init__(self, upstream: Filter, fn: Callable) -> None: | |
|
||
Args: | ||
upstream: the upstream message filter. | ||
fn: adapter implementation as a callable. | ||
fn: a callable that takes messages as arguments and returns some | ||
data to be signaled (i.e. propagated down the filter chain). | ||
If none is returned, no message signaling will occur. | ||
""" | ||
super().__init__() | ||
self.fn = fn | ||
self.connection = upstream.registerCallback(self.add) | ||
|
||
def add(self, *messages: Any) -> None: | ||
"""Adds new `messages` to the adapter.""" | ||
self.signalMessage(self.fn(*messages)) | ||
result = self.fn(*messages) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @amessing-bdai ended up going with the trivial implementation. There is a way, an |
||
if result is not None: | ||
self.signalMessage(result) | ||
|
||
|
||
class Tunnel(Filter): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
black
decided it was time to reformat 🤷♂️There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a line length limit for black.