- add subscription via MessageDispatcher

This commit is contained in:
jens
2020-11-25 08:41:43 +01:00
parent 89922a4984
commit 4cde362642
6 changed files with 27 additions and 29 deletions
+10 -4
View File
@@ -45,9 +45,11 @@ class Value:
class MessageDispatcher(IConnection):
def __init__(self):
def __init__(self, auto_subscribe=False, loop=None):
self.msg_handlers: MsgIo = []
self.state = None
self.state = asyncio.Queue(loop=loop)
self.auto_subscribe = auto_subscribe
def msgio_get(self, key):
obj = MsgIo(key, self.send)
@@ -56,10 +58,14 @@ class MessageDispatcher(IConnection):
return obj
return None
def on_connect(self, loop):
self.state = asyncio.Queue(loop=loop)
async def on_connect(self):
if self.auto_subscribe:
for handler in self.msg_handlers:
key = handler.get_key()
print("Would subscribe {}".format(key))
await self.send({'+': key})
def on_disconnect(self):
async def on_disconnect(self):
pass
async def on_recv(self, data):