def mqtt_subscribe(self, topics, packet_id): """ :param topics: array of topics [{'filter':'/a/b', 'qos': 0x00}, ...] :return: """ subscribe = SubscribePacket.build(topics, packet_id) yield from self.outgoing_queue.put(subscribe) waiter = futures.Future(loop=self._loop) self._subscriptions_waiter[subscribe.variable_header.packet_id] = waiter return_codes = yield from waiter del self._subscriptions_waiter[subscribe.variable_header.packet_id] return return_codes
def mqtt_subscribe(self, topics, packet_id): """ :param topics: array of topics [{'filter':'/a/b', 'qos': 0x00}, ...] :return: """ subscribe = SubscribePacket.build(topics, packet_id) yield from self.outgoing_queue.put(subscribe) waiter = futures.Future(loop=self._loop) self._subscriptions_waiter[ subscribe.variable_header.packet_id] = waiter return_codes = yield from waiter del self._subscriptions_waiter[subscribe.variable_header.packet_id] return return_codes
def mqtt_subscribe(self, topics, packet_id): """ :param topics: array of topics [{'filter':'/a/b', 'qos': 0x00}, ...] :return: """ # Build and send SUBSCRIBE message subscribe = SubscribePacket.build(topics, packet_id) yield from self._send_packet(subscribe) # Wait for SUBACK is received waiter = futures.Future(loop=self._loop) self._subscriptions_waiter[subscribe.variable_header.packet_id] = waiter return_codes = yield from waiter del self._subscriptions_waiter[subscribe.variable_header.packet_id] return return_codes
async def mqtt_subscribe(self, topics, packet_id): """ :param topics: array of topics [{'filter':'/a/b', 'qos': 0x00}, ...] :return: """ waiter = Future() self._subscriptions_waiter[packet_id] = waiter try: # Build and send SUBSCRIBE message subscribe = SubscribePacket.build(topics, packet_id) await self._send_packet(subscribe) # Wait for SUBACK is received return_codes = await waiter.get() finally: del self._subscriptions_waiter[packet_id] return return_codes
def mqtt_subscribe(self, topics, packet_id): """ :param topics: array of topics [{'filter':'/a/b', 'qos': 0x00}, ...] :return: """ def acknowledged_predicate(): if self.subscriptions[subscribe.variable_header.packet_id].state == "acknowledged": return True else: return False subscribe = SubscribePacket.build(topics, packet_id) yield from self.outgoing_queue.put(subscribe) subscription = Subscription(subscribe.variable_header.packet_id, topics) subscription.subscribe() self.subscriptions[subscribe.variable_header.packet_id] = subscription yield from self._subscriptions_changed.acquire() yield from self._subscriptions_changed.wait_for(acknowledged_predicate) subscription = self.subscriptions.pop(subscribe.variable_header.packet_id) self._subscriptions_changed.release() return subscription