platypush/platypush/bus/__init__.py

26 lines
579 B
Python
Raw Normal View History

2017-12-18 01:10:51 +01:00
from queue import Queue
class Bus(object):
""" Main local bus where the daemon will listen for new messages """
def __init__(self, on_msg=None):
2017-12-18 01:10:51 +01:00
self.bus = Queue()
self.on_msg = on_msg
def post(self, msg):
""" Sends a message to the bus """
self.bus.put(msg)
def loop_forever(self):
""" Reads messages from the bus """
if not self.on_msg: return
2017-12-18 01:10:51 +01:00
while True:
try:
self.on_msg(self.bus.get())
except KeyboardInterrupt:
return
# vim:sw=4:ts=4:et: