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

mpsc: add owned refs #62

Open
hawkw opened this issue Apr 29, 2022 · 1 comment
Open

mpsc: add owned refs #62

hawkw opened this issue Apr 29, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@hawkw
Copy link
Owner

hawkw commented Apr 29, 2022

Currently, the SendRef and RecvRef types returned by thingbuf::mpsc's senders and receivers contain a borrowed reference to the channel's queue. This means that a Ref from a channel cannot live for the 'static lifetime. However, because the channel's queue is either internally reference counted (in the case of the dynamically allocated MPSCs) or lives in a static variable (in the case of the static MPSCs), it should also be possible to create a reference to a queue slot that is 'static.

We could add an API like tokio::sync::mpsc's Sender::reserve_owned, which clones the internal Arc around the channel's shared data and returns a permit whose lifetime is not bound to a borrow of the Sender handle that produced it.

This could potentially enable some neat stuff, like using a thingbuf mpsc::Receiver of Vec<u8>s as a http_body::Body without having to copy data out of the thingbuf --- in this case, an OwnedRecvRef type could be passed directly into hyper or another HTTP library, and when the library finishes sending the body chunk, that ref is dropped, returning the buffer to the pool.

@hawkw hawkw added the enhancement New feature or request label Apr 29, 2022
@hawkw hawkw self-assigned this Apr 29, 2022
@hawkw
Copy link
Owner Author

hawkw commented Apr 30, 2022

This should be pretty straightforward but may require a bit of refactoring internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant