Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Await/Promise for receiving next message feature discussion #40

Open
cameronelliott opened this issue Dec 1, 2020 · 3 comments
Open

Comments

@cameronelliott
Copy link

This is the 2nd feature I would like to discuss adding to the library.

Which is also a feature request for an excellent raw websockets library.

The feature is described here

Basically, it allows promises to be used to await the next message received, rather than just relying on a callback.

Example from linked issue:

await ws.open();

while (true) {
  data = await ws.recv();
  ws.send(data);
}

See discussion in raw websockets project for more details: here

I make try to implement this, but I am not a fantastic JS, nor promises programmer, but if someone else
wants to help or try to do this, please let me know!

Thanks for this awesome async/MQTT library!

@cameronelliott
Copy link
Author

I would also like feedback from the maintainers if they would be interested in a PR for this feature?

@cameronelliott
Copy link
Author

Actually, I would love to get some feedback/input from the maintainers on the use or submission of this functionality.
I will sit tight. I won't submit PR until after discussion.
https://github.com/x186k/async-mqtt-x186k

@RangerMauve
Copy link
Contributor

Regarding awaiting events, I think the EventEmitter.once(emitter, eventName) API in the node docs is what people tend to use.

I think it'd be cool to return async iterables from events like for await (const data of mqtt.on('event')) { etc }

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

No branches or pull requests

2 participants