Skip to content

Commit

Permalink
Merge pull request #10 from compas-dev/not-fail-on-off
Browse files Browse the repository at this point in the history
Ensure no fail at `unsubscribe_by_id`
  • Loading branch information
gonzalocasas authored Apr 2, 2024
2 parents fd8ae59 + c9ec42d commit 49dc280
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

* Ensure calling `off()` or `unsubscribe()` does not fail if the callback is not present in the registered event callbacks.

### Removed


Expand Down
12 changes: 10 additions & 2 deletions src/compas_eve/event_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,19 @@ def g(*args, **kwargs):

def off(self, event, f):
"""Removes the function ``f`` from ``event``."""
self._events[event].pop(f)
with self._event_lock:
if f in self._events[event]:
return self._events[event].pop(f)

return None

def remove_listener(self, event, f):
"""Removes the function ``f`` from ``event``."""
self._events[event].pop(f)
with self._event_lock:
if f in self._events[event]:
return self._events[event].pop(f)

return None

def remove_all_listeners(self, event=None):
"""Remove all listeners attached to ``event``.
Expand Down

0 comments on commit 49dc280

Please sign in to comment.