Helpers¶
Messaging¶
The backbone of the local messaging system is a dispatching mechanism based on the publish-subscribe analogy. Once a dispatcher object is created, objects can Dispatcher.subscribe() to messages from other objects and be notified when other objects Dispatcher.send() a message to the dispatcher:
from concert.helpers import Dispatcher
def handle_message(sender):
print("{0} send me a message".format(sender))
dispatcher = Dispatcher()
obj = {}
dispatcher.subscribe(obj, 'foo', handle_message)
dispatcher.send(obj, 'foo')
If not stated otherwise, users should use the global dispatcher for sending and receiving messages.
- concert.helpers.dispatcher¶
A global Dispatcher instance used by all devices.