Skip to content

wait_msg() return op as indication if there was a message#528

Closed
meirarmon wants to merge 1 commit intomicropython:masterfrom
meirarmon:master
Closed

wait_msg() return op as indication if there was a message#528
meirarmon wants to merge 1 commit intomicropython:masterfrom
meirarmon:master

Conversation

@meirarmon
Copy link
Copy Markdown
Contributor

As indicated in this issue: #328, it would be useful if wait_msg() would return a value if a message was received.
A common use case using this library would be:

def callback(topic, msg):
    print(topic, msg)


async def check_messages(mqtt_client, interval):
    while True:
        mqtt_client.check_msg()
        await asyncio.sleep(interval)

In the above scenario, if more than one message was published to the topic being subscribed to, it will still get consumed every seconds. If this change is merged, we would be able to do:

def callback(topic, msg):
    print(topic, msg)


async def check_messages(mqtt_client, interval):
    while True:
        while mqtt_client.check_msg() is not None:
            continue
        await asyncio.sleep(interval)

And any waiting messages will get consumed immediately.

@dpgeorge
Copy link
Copy Markdown
Member

dpgeorge commented Oct 4, 2022

Thanks for the contribution, this is a nice and simple improvement. Rebased and merged in b50d346

@dpgeorge dpgeorge closed this Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants