A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://glue-core.readthedocs.io/en/latest/api/glue.core.hub.Hub.html below:

Hub — Glue documentation

Hub#
class glue.core.hub.Hub(*args)[source]#

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

broadcast(message)[source]#

Broadcasts a message to all subscribed objects.

Parameters:

message (Message) – The message to broadcast

delay_callbacks()[source]#
get_handler(subscriber, message)[source]#
ignore_callbacks(ignore_type)[source]#
is_subscribed(subscriber, message)[source]#

Test whether the subscriber has subscribed to a given message class

Parameters:
  • 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(subscriber, message_class, handler=None, filter=<function Hub.<lambda>>, priority=10)[source]#

Subscribe an object to a type of message class.

Parameters:
  • 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.

Raises:

InvalidMessage: If the input class isn’t a Message class

InvalidSubscriber: If the input subscriber isn’t a HubListener object.

unsubscribe(subscriber, message)[source]#

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_all(subscriber)[source]#

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