Skip to content

Commit

Permalink
Support using multiple/concurrent EventListeners
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Sep 11, 2024
1 parent 5f0ff21 commit 9781644
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions griptape/events/event_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def add_event_listeners(self, event_listeners: list[EventListener]) -> list[Even
return [self.add_event_listener(event_listener) for event_listener in event_listeners]

def remove_event_listeners(self, event_listeners: list[EventListener]) -> None:
for event_listener in event_listeners:
self.remove_event_listener(event_listener)
with self._thread_lock:
for event_listener in event_listeners:
self.remove_event_listener(event_listener)

def add_event_listener(self, event_listener: EventListener) -> EventListener:
with self._thread_lock:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/events/test_event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def test_add_remove_event_listener(self, pipeline):
mock1 = Mock()
mock2 = Mock()
# duplicate event listeners will only get added once
event_listener_1 = EventBus.add_event_listener(EventListener(mock1, event_types=[StartPromptEvent]))
EventBus.add_event_listener(EventListener(mock1, event_types=[StartPromptEvent]))
event_listener_1 = EventBus.add_event_listener(EventListener(mock1, id="1", event_types=[StartPromptEvent]))
EventBus.add_event_listener(EventListener(mock1, id="1", event_types=[StartPromptEvent]))

event_listener_3 = EventBus.add_event_listener(EventListener(mock1, event_types=[FinishPromptEvent]))
event_listener_4 = EventBus.add_event_listener(EventListener(mock2, event_types=[StartPromptEvent]))
Expand Down

0 comments on commit 9781644

Please sign in to comment.