-
Notifications
You must be signed in to change notification settings - Fork 17
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
Allow splitting client to support concurrent read/publish #27
base: master
Are you sure you want to change the base?
Conversation
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.
👍 I just added some comments. But I think e.g. the expects seem to be part of the existing code base anyway already.
I think this is an interesting feature request. Unfortunately I have issues with the way it's currently implemented in your branch. From a brief look it seems quite a lot of code is duplicated between the new Is there a way for the |
Thank you for the feedback. I'll work on it sometime this week:
|
I have changed the API to something I am more comfortable with, removed code duplication and added some documentation. The new API works by allowing the creation of An example how this works:
The original Client instance remains usable after creating one or more publishers. |
I'm using this library from a web application used to control IoT devices. I would like to publish a message in response to a web call.
The current API does not allow concurrent use of the Client.
In this PR I implemented a
into_split
method which, much like thetokio::net::TcpStream::into_split
will split the Client into two halves: a reading half and a publishing half.The publishing half is Sync and clonable, which allows use from multiple threads.
The reading half is not, and remains usable from only a single thread.
The current implementation in this PR is very rough (just copied various methods from the Client) and serves my purpose.
If the maintainer of this repository is interested in this functionality, I will clean it up further.
EDIT:
API design changed a bit since original design described above. See #27 (comment)