sbtinstruments / aiomqtt

The idiomatic asyncio MQTT client, wrapped around paho-mqtt
https://sbtinstruments.github.io/aiomqtt
BSD 3-Clause "New" or "Revised" License
393 stars 71 forks source link

using early return #223

Closed AlfaBravoX closed 1 year ago

AlfaBravoX commented 1 year ago

This is probably not a bug, but I would like to use early return within async for message in messages: loop

ie.

async for message in messages:
  try:
      if message.topic.matches("not-interesting-topic/#"):
          print(f"early return")
          return
      elif message.topic.matches("interesting-topic/#"):
         do something
      ...

return used in first condition obviously breaks listening process and no more messages are received if return is applied. Is there a change to exit listening loop for only one message and continue receiving messages?

I am able to rewrite the code to completely avoid returns but I prefer to keep using it.

AlfaBravoX commented 1 year ago

for anyone meeting this scenario, using continue instead return fixes this issue