def async_handle_subscribe(request, subscribed_clients, state_variables):
callback_url = request.headers.get('CALLBACK')[1:-1]
sid = 'uuid:' + str(uuid.uuid4())
subscribed_clients[sid] = callback_url
headers = {
'SID': sid
}
@asyncio.coroutine
def async_push_later(state_variable):
yield from asyncio.sleep(0.5)
yield from state_variable.async_notify_listeners()
for state_variable in state_variables.values():
LOGGER.debug('Pushing state_variable on SUBSCRIBE: %s', state_variable.name)
asyncio.get_event_loop().create_task(async_push_later(state_variable))
return web.Response(status=200, headers=headers)
#endregion
#region Unsubscribe
评论列表
文章目录