Skip to content

Commit

Permalink
Fix register callback
Browse files Browse the repository at this point in the history
  • Loading branch information
enriquetomasmb committed Nov 19, 2024
1 parent 7662a11 commit 60c91ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 2 additions & 6 deletions nebula/core/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,10 @@ def __init__(
)

# Register additional callbacks
self._event_manager.register_event(
(
nebula_pb2.FederationMessage,
nebula_pb2.FederationMessage.Action.REPUTATION,
),
self._event_manager.register_callback(
self._reputation_callback,
# ... add more callbacks here
)
# ... add more callbacks here

@property
def cm(self):
Expand Down
8 changes: 8 additions & 0 deletions nebula/core/eventmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def _register_default_callbacks(self, default_callbacks):
else:
raise ValueError("The callback must be decorated with @event_handler.")

def register_callback(self, callback):
"""Registers a callback for an event."""
handler_info = getattr(callback, "_event_handler", None)
if handler_info is not None:
self.register_event(handler_info, callback)
else:
raise ValueError("The callback must be decorated with @event_handler.")

def register_event(self, handler_info, callback):
"""Records a callback for a specific event."""
if callable(callback):
Expand Down

0 comments on commit 60c91ef

Please sign in to comment.