-
Notifications
You must be signed in to change notification settings - Fork 71
Cloning channels in public interface. #172
base: master
Are you sure you want to change the base?
Conversation
…ness of channels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. I don't see any issues with cloning the tx channel. I was actually just running into this issue myself. Going to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Played with this a bit today. I was able to do a whole load of concurrent requests and everything seemed to work nicely. As far as I'm concerned this is a good pull. I did run into some ALPN issues but that's a separate issue I think.
Hello @tekjar. Could you please take a look into this? |
@leoniloris I'll check this today. Wish github had some sort of reminder option |
@leoniloris @TheBestJohn I'm not sure if cloning the channel everytime you do a publish is the right way to go here because I'm not sure of the costs involved (Remember channel implementation doubling the capacity for every clone). I want to understand how "usefulness of channels" and removing &muts are related. What wrong with cloning the client itself? |
Thanks for the answer @tekjar !
Do you have a suggestion? |
Adding my use case here, I've been playing with connecting this library to the Rocket web framework. I'm receiving a POST request, doing some auth and validation, then sending an MQTT message. Rocket can manage the state of anything with the as a note, if you want to do this you will have to excise the ALPN functionality as Rocket uses an older version of Ring and thus older rustls, and thus has a different type for the ALPN configurations |
Also according to the documentation on crossbeam here.
and shortly thereafter they say that
This seems to suggest that the two methods to do this are about the same. |
@TheBestJohn crossbeam channels are convenient. We don't have to use &mut to send data over crossbeam channel. But we don't use crossbeam channel to handle user requests as it doesn't support futures The problem with futures channel is capacity doubling for every temporary clone. I don't think this is the correct way to go here. I think @stjepang is working on crossbeam channel for async-std. We'll have to wait and see
Just to make sure that I understand this completely, You have a struct which has both rocket handler and |
Oh it's not using crossbeam there. Sorry, my mistake. edit: Ah and looking into this I can see you here: crossbeam-rs/crossbeam-channel#22 I've gone down the rabbit-hole and ended up here: https://stjepang.github.io/2019/03/02/new-channels.html Pretty interesting read and I'm starting to get what the problem is.
Sort of. It just seems the nature of this lib being focused on async with the server, lends itself to the idea that the library should be able to accommodate an application or library's interaction with rumqtt in an async manner as well. Maybe that's naïve and asking too much? I don't know, and please don't take it as a criticism of your work. I don't fully understand the library but hope to know more. There's a thread on mutable refs in State here I can provide a MWE for demo purposes as well if you'd like to take a look. |
Yeah a minimal example will help |
Here you are. It uses my fork of rumqtt because of issues with rustls versions. Swap it back to head if you'd like to see those too |
Updated the MWE to use Rocket head directly with this branch. Rocket updated it's TLS stuff so the ALPN issues no longer arise. |
Closes #171
The publish method requires a mutable reference of self, but it does not seem to be really correct to mutate it in the publish/subscribe etc since those represent a command being sent to a channel.
This PR removes the
mutable
reference by cloning the channels, since, channels are supposed to be cloned by design.