Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
improve ref man for registration package
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinAV committed Sep 4, 2023
1 parent e16495e commit 67ad5c6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/taipy/core/notification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
Package for notifications about changes on `Core^` service entities.
The Core service generates 'Event^' objects to track changes on entities.
These events are then relayed to a 'Notifier^', which handles the dispatch
The Core service generates `Event^` objects to track changes on entities.
These events are then relayed to a `Notifier^`, which handles the dispatch
to consumers interested in specific event topics.
To subscribe, a consumer needs to invoke the `Notifier.register()^` method.
Expand Down
15 changes: 4 additions & 11 deletions src/taipy/core/notification/core_event_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@ class CoreEventConsumerBase(threading.Thread):
It should be subclassed, and the `process_event` method should be implemented to define
the custom logic for handling incoming events.
Attributes:
queue (SimpleQueue): The queue from which events will be consumed.
Methods:
start(): Start the event consumer thread.
stop(): Stop the event consumer thread.
run(): The main thread execution logic that continuously consumes events from the queue
and delegates their processing to the `process_event` method.
process_event(event: Event): This method should be overridden in subclasses to define
how events are processed.
Example usage:
```python
Expand All @@ -51,6 +40,10 @@ def process_event(self, event: Event):
Subclasses should implement the `process_event` method to define their specific event handling behavior.
Attributes:
queue (SimpleQueue): The queue from which events will be consumed.
"""

def __init__(self, registration_id: str, queue: SimpleQueue):
Expand Down
12 changes: 10 additions & 2 deletions src/taipy/core/notification/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ def register(

@classmethod
def unregister(cls, registration_id: str):
"""Unregister a listener."""
"""Unregister a listener.
Parameters:
registration_id (RegistrationId^): The registration id returned by the `register` method.
"""
to_remove_registration: Optional[_Registration] = None

for _, registrations in cls._topics_registrations_list.items():
Expand All @@ -109,7 +113,11 @@ def unregister(cls, registration_id: str):

@classmethod
def publish(cls, event):
"""Publish a `Core^` service event to all registered listeners whose topic matches the event."""
"""Publish a `Core^` service event to all registered listeners whose topic matches the event.
Parameters:
event (Event^): The event to publish.
"""
for topic, registrations in cls._topics_registrations_list.items():
if Notifier._is_matching(event, topic):
for registration in registrations:
Expand Down
3 changes: 1 addition & 2 deletions src/taipy/core/notification/registration_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
from typing import NewType

RegistrationId = NewType("RegistrationId", str)
RegistrationId.__doc__ = """Type that holds a `Registration^` identifier. It can be used to instantiate a
`CoreEventConsumerBase^`."""
RegistrationId.__doc__ = """Registration identifier. It can be used to instantiate a `CoreEventConsumerBase^`."""

0 comments on commit 67ad5c6

Please sign in to comment.