Bases: object
The hub manages communication between subscribers.
Objects subscribe()
to receive specific message types. When a message is passed to broadcast()
, the hub observes the following protocol:
For each subscriber, it looks for a message class subscription that is a parent class of the input message type (if several are found, the most-subclassed one is chosen)
If one is found, it calls the subscriptions filter(message) class (if provided)
If filter(message) == True, it calls handler(message) (or notify(message) if handler wasn’t provided).
Any arguments that are passed to Hub will be registered to the new hub object.
Methods Summary
Methods Documentation
Broadcasts a message to all subscribed objects.
message (Message
) – The message to broadcast
Test whether the subscriber has subscribed to a given message class
subscriber – The subscriber to test
message – The message class to test
Returns:
True if the subscriber/message pair have been subscribed to the hub
Subscribe an object to a type of message class.
subscriber (HubListener
) – The subscribing object
message_class – A Message
class to subscribe to
handler – An optional function of the form handler(message) that will receive the message on behalf of the subscriber. If not provided, this defaults to the HubListener’s notify method
filter – An optional function of the form filter(message). Messages are only passed to the subscriber if filter(message) == True. The default is to always pass messages.
priority – An optional integer to set the priority of the handler. Handlers are sorted such that higher priority handlers get called first when broadcasting a message.
InvalidMessage: If the input class isn’t a Message
class
InvalidSubscriber: If the input subscriber isn’t a HubListener object.
Remove a (subscriber,message) pair from subscription list. The handler originally attached to the subscription will no longer be called when broadcasting messages of type message
Unsubscribe the object from any subscriptions.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4