Last active
July 15, 2020 13:30
-
-
Save tonyroberts/4603431fe74c8ed860683b44ea896047 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use a single global message broker for all topics | |
_global_message_broker = MessageBroker() | |
def publish(topic, value): | |
"""Publishes a value on a topic for a subscriber to receive""" | |
_global_message_broker.publish(topic, value) | |
def subscribe(topic, callback): | |
"""Subscribes to a topic. | |
The subscriber callback is called with the topic value whenever | |
the a value is published to that topic, and with the initial | |
value if there is one. | |
""" | |
_global_message_broker.subscribe(topic, callback) | |
def unsubscribe(topic, callback): | |
"""Unsubscribe from a topic. | |
The topic and callback must have previously be passed to 'subscribe'. | |
""" | |
_global_message_broker.unsubscribe(topic, callback) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment