InFlightRequest

Struct InFlightRequest 

Source
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>

Source

pub fn get(&self) -> &Request<Req>

Returns a reference to the request.

Source

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:

  1. The channel that yielded this request receives a cancellation message for this request.
  2. The request deadline is reached.
  3. 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§

Source§

impl<Req, Res> Debug for InFlightRequest<Req, Res>
where Req: Debug, Res: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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>
where Req: Send, Res: Send,

§

impl<Req, Res> Sync for InFlightRequest<Req, Res>
where Req: Sync, Res: Send,

§

impl<Req, Res> Unpin for InFlightRequest<Req, Res>
where Req: Unpin,

§

impl<Req, Res> !UnwindSafe for InFlightRequest<Req, Res>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more