Skip to content

Commit 40df9b8

Browse files
committed
Add Body::poll_healthy
1 parent e5b462a commit 40df9b8

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
@@ -50,6 +50,21 @@ pub trait Body {
5050
cx: &mut Context<'_>,
5151
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>>;
5252

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

0 commit comments

Comments
 (0)