Need help understanding events in mqtt_as.py #12466
-
I'm a newbie when it comes to using the event interface in mqtt_as.py. I've tried the range_ex.py example in the mqtt_as distribution and I've cookie-cuttered code from that example into my own code and both work great. But there's a code construct that I just don't understand:
How is this legal Python? MQTTClient doesn't have an "up" method (or "down" method either), so how can the line "await client.up.wait()" not raise an error? I know for this code to work it requires "config["queue_len"] = 4" but I don't understand how this this apparently changes the semantics of the statement "client.up.wait()". Can someone please point me to documentation that explains what's going on. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
So the code is (async) waiting for these events to be set elsewhere in the mqtt library. |
Beta Was this translation helpful? Give feedback.
-
OK. I got it now. The asyncio tutorial helped, as did a careful reading of section 3.5 Event based interface of the mqtt_as documentation. I originally got confused because when I looked at mqtt_as.py I didn't find either an "up" or "down" method, and it was, like, "how can this possibly work?" And I'm all for the Event-based approach to mqtt_as. It was my desire to move away from callbacks that got me started down this path. Thanks for the answers! |
Beta Was this translation helpful? Give feedback.
up
anddown
here areasyncio.Event()
objects, see https://github.com/peterhinch/micropython-mqtt/blob/f9290c68b0459e2841e0565cb6b45bc636f698bd/mqtt_as/mqtt_as.py#L154So the code is (async) waiting for these events to be set elsewhere in the mqtt library.