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

Add Body::poll_progress #90

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add Body::poll_healthy
  • Loading branch information
sfackler committed Jan 23, 2024
commit 40df9b8b282f80e5ce02247bee4a99cbe69d7707
15 changes: 15 additions & 0 deletions http-body/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ pub trait Body {
cx: &mut Context<'_>,
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>>;

/// Determine if the body is still in a healthy state without polling for the next frame.
///
/// `Body` consumers can use this method to check if the body has entered an error state even
/// when the consumer is not yet ready to try to read the next frame. Since healthiness is not
/// an operation that completes, this method returns just a `Result` rather than a `Poll`.
///
/// For example, a `Body` implementation could maintain a timer counting down betwen
sfackler marked this conversation as resolved.
Show resolved Hide resolved
/// `poll_frame` calls and report an error from `poll_healthy` when time expires.
///
/// The default implementation returns `Ok(())`.
fn poll_healthy(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Result<(), Self::Error> {
Copy link
Author

Choose a reason for hiding this comment

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

If we wanted this to be more poll-like we could have a return value of Poll<Result<Void, Self::Error>>>.

let _ = cx;
Ok(())
}

/// Returns `true` when the end of stream has been reached.
///
/// An end of stream means that `poll_frame` will return `None`.
Expand Down