Code Monkey home page Code Monkey logo

Comments (4)

frederikaalund avatar frederikaalund commented on September 26, 2024 1

I've written an idiomatic asyncio-based interface around paho-mqtt: asyncio-mqtt

It replaces the callback-based interface with async with and async for statements. Feel free to take inspiration from asyncio-mqtt's interface and implementation. :)

#70

from gmqtt.

eerimoq avatar eerimoq commented on September 26, 2024 1

Another alternative is mqttools. However, it only implements MQTT version 5.0, and not the older 3.x versions.

from gmqtt.

Lenka42 avatar Lenka42 commented on September 26, 2024

@liamdiprose we do not support such behaviour and do not plan to implement it.
I guess you can implement behaviour similar to async with gmqtt.connect('mqtt.flespi.io') as client: on your own creating context-manager class which will do connect on enter and disconnect on exit.

But implementation of behaviour similar to this one: async for message in client.subscribe('TEST/#', qos=0): is hardly possible now. But I think it might be related to issue #60

from gmqtt.

liamdiprose avatar liamdiprose commented on September 26, 2024

Hi @Lenka42, Thanks for the tips, I might have a go at the context manager class this week.

The async for line is closer to question I was trying to ask: Using an awaitable object instead of callbacks.

message = await client.subscribe(...)

Asyncio has the Future class, which was made to "bridge low-level callback-based code with high-level async/await code". I'll have a go at wrapping gmqtt's on_connect and on_message callbacks and see how it goes.

With the global callbacks (#60), the Future implementation probably won't work for more than one subscription at a time.

Would you be open to a Pull Request?

from gmqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.