Skip to content

Commit 1a405e3

Browse files
committed
Add Body::poll_healthy
1 parent 7bf321a commit 1a405e3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

http-body/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ pub trait Body {
4747
cx: &mut Context<'_>,
4848
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>>;
4949

50+
/// Determine if the body is still in a healthy state without polling for the next frame.
51+
///
52+
/// `Body` consumers can use this method to check if the body has entered an error state even
53+
/// when the consumer is not yet ready to try to read the next frame. Since healthiness is not
54+
/// an operation that completes, this method returns just a `Result` rather than a `Poll`.
55+
///
56+
/// For example, a `Body` implementation could maintain a timer counting down betwen
57+
/// `poll_frame` calls and report an error from `poll_healthy` when time expires.
58+
///
59+
/// The default implementation returns `Ok(())`.
60+
fn poll_healthy(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Result<(), Self::Error> {
61+
let _ = cx;
62+
Ok(())
63+
}
64+
5065
/// Returns `true` when the end of stream has been reached.
5166
///
5267
/// An end of stream means that `poll_frame` will return `None`.

0 commit comments

Comments
 (0)