- add subscription via MessageDispatcher
This commit is contained in:
+10
-4
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user