Skip to content

Commit

Permalink
Allow checking whether a ResponseChannel is still open.
Browse files Browse the repository at this point in the history
Also expand the commentary on `send_response` to indicate that
responses may be discard if they come in too late.
  • Loading branch information
romanb committed Jun 27, 2020
1 parent 9c6e6b4 commit 7bfdff5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions protocols/request-response/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ pub struct ResponseChannel<TResponse> {
sender: oneshot::Sender<TResponse>,
}

impl<TResponse> ResponseChannel<TResponse> {
/// Checks whether the response channel is still open, i.e.
/// the `RequestResponse` behaviour is still waiting for a
/// a response to be sent via [`RequestResponse::send_response`]
/// and this response channel.
///
/// If the response channel is no longer open then the inbound
/// request timed out waiting for the response.
pub fn is_open(&self) -> bool {
!self.sender.is_canceled()
}
}

/// The (local) ID of an outgoing request.
///
/// See [`RequestResponse::send_request`].
Expand Down Expand Up @@ -330,6 +343,10 @@ where

/// Initiates sending a response to an inbound request.
///
/// If the `ResponseChannel` is already closed due to a timeout,
/// the response is discarded and eventually [`RequestResponseEvent::InboundFailure`]
/// is emitted by `RequestResponse::poll`.
///
/// The provided `ResponseChannel` is obtained from a
/// [`RequestResponseMessage::Request`].
pub fn send_response(&mut self, ch: ResponseChannel<TCodec::Response>, rs: TCodec::Response) {
Expand Down

0 comments on commit 7bfdff5

Please sign in to comment.