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

util: add a channel body #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

util: add a channel body #100

wants to merge 1 commit into from

Conversation

davidpdrsn
Copy link
Member

Adds a new body type that's backed by a tokio::sync::mpsc channel. Inspired by hyper's old Body::channel.

@davidpdrsn davidpdrsn changed the title Add channel body util: add a channel body Nov 19, 2023
seanmonstar
seanmonstar previously approved these changes Nov 20, 2023

impl<D, E> Sender<D, E> {
/// Send a frame on the channel.
pub async fn send(&self, frame: Frame<D>) -> Result<(), SendError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though it's not required internally, should we make these all &mut self?

/// A body backed by a channel.
pub struct Channel<D, E = std::convert::Infallible> {
rx_frame: mpsc::Receiver<Frame<D>>,
rx_error: mpsc::Receiver<E>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a oneshot channel work? It should be a smaller struct, and use less memory wen sending the error (the mpsc channel reserves blocks).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I thought it wouldn't be possible because one shot::Receiver doesn't have a poll_recv method but I suppose I can call Future::poll instead 🤔 I'll try that.

@seanmonstar seanmonstar dismissed their stale review November 20, 2023 21:44

Didn't mean to approve just yet

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

Successfully merging this pull request may close these issues.

2 participants