pub struct InFlightRequest<Req, Res> { /* private fields */ }Expand description
A request produced by Channel::requests.
If dropped without calling execute, a cancellation message will
be sent to the Channel to clean up associated request state.
Implementations§
Source§impl<Req, Res> InFlightRequest<Req, Res>
impl<Req, Res> InFlightRequest<Req, Res>
Sourcepub async fn execute<S>(self, serve: S)where
Req: RequestName,
S: Serve<Req = Req, Resp = Res>,
pub async fn execute<S>(self, serve: S)where
Req: RequestName,
S: Serve<Req = Req, Resp = Res>,
Returns a future that executes the request using the given service function. The service function’s output is automatically sent back to the Channel that yielded this request. The request will be executed in the scope of this request’s context.
The returned future will stop executing when the first of the following conditions is met:
- The channel that yielded this request receives a cancellation message for this request.
- The request deadline is reached.
- The service function completes.
If the returned Future is dropped before completion, a cancellation message will be sent to the Channel to clean up associated request state.
§Example
use tarpc::{
context,
client::{self, NewClient},
server::{self, BaseChannel, Channel, serve},
transport,
};
use futures::prelude::*;
#[tokio::main]
async fn main() {
let (tx, rx) = transport::channel::unbounded();
let server = BaseChannel::new(server::Config::default(), rx);
let NewClient { client, dispatch } = client::new(client::Config::default(), tx);
tokio::spawn(dispatch);
tokio::spawn(async move {
let mut requests = server.requests();
while let Some(Ok(in_flight_request)) = requests.next().await {
in_flight_request.execute(serve(|_, i| async move { Ok(i + 1) })).await;
}
});
assert_eq!(client.call(context::current(), 1).await.unwrap(), 2);
}Trait Implementations§
Auto Trait Implementations§
impl<Req, Res> Freeze for InFlightRequest<Req, Res>where
Req: Freeze,
impl<Req, Res> !RefUnwindSafe for InFlightRequest<Req, Res>
impl<Req, Res> Send for InFlightRequest<Req, Res>
impl<Req, Res> Sync for InFlightRequest<Req, Res>
impl<Req, Res> Unpin for InFlightRequest<Req, Res>where
Req: Unpin,
impl<Req, Res> !UnwindSafe for InFlightRequest<Req, Res>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more