pub struct PreparedRequest<T> { /* private fields */ }Expand description
A request that has not been published to its connection.
Created by ConnectionTo::prepare_request or
ConnectionTo::prepare_request_to. Preparation serializes the request but
does not register a pending reply or enqueue outgoing traffic. Dropping this
value sends neither the request nor a cancellation notification.
A consuming method publishes the request synchronously:
on_receiving_result,on_receiving_ok_result, andforward_response_toregister ordered response handling before publication. When a peer response is routed during its original dispatch, later inbound messages wait for that handling to finish.block_taskpublishes immediately and returns an unordered response future. Publication does not wait for its first poll.detachpublishes immediately and discards the response.
Ordered callbacks must do bounded work and must not await later inbound
traffic on the same connection. EOF failures and responses routed through a
retained ResponseRouter after their original dispatch have no ordering
barrier. See crate::concepts::ordering.
§Errors
Preparation and publication failures are delivered to the selected response
consumer. Callback-style methods return an error if their task cannot be
registered; in that case the request is not published. detach
returns preparation or publication errors directly because it has no response
consumer. A callback returning an error terminates the connection.
Implementations§
Source§impl<T> PreparedRequest<T>
impl<T> PreparedRequest<T>
Sourcepub fn map<U>(
self,
map_fn: impl FnOnce(T) -> Result<U, Error> + 'static + Send,
) -> PreparedRequest<U>where
T: 'static,
pub fn map<U>(
self,
map_fn: impl FnOnce(T) -> Result<U, Error> + 'static + Send,
) -> PreparedRequest<U>where
T: 'static,
Map a successful response without publishing the request.
The mapper has the same contract as SentRequest::map.
Sourcepub fn forward_cancellation_from(self, source: RequestCancellation) -> Self
pub fn forward_cancellation_from(self, source: RequestCancellation) -> Self
Register a cancellation source without publishing the request.
After publication, cancellation is forwarded while awaiting the response,
as described by SentRequest::forward_cancellation_from.
Sourcepub fn block_task(self) -> impl Future<Output = Result<T, Error>>
pub fn block_task(self) -> impl Future<Output = Result<T, Error>>
Publish now and return an unordered future for the response.
The request is enqueued during this call, not when the future is first
polled. Dropping that future asks the peer to cancel a still-outstanding
request. Await it only outside the dispatch loop; awaiting it in an
incoming handler deadlocks just like SentRequest::block_task.
§Errors
The returned future delivers preparation, publication, and response errors.
Sourcepub fn detach(self) -> Result<(), Error>
pub fn detach(self) -> Result<(), Error>
Publish now and discard the eventual response without cancelling.
§Errors
Returns immediate preparation or enqueue failures. Later local transformation errors and peer response errors are discarded along with successful responses. Transport failures still propagate through the connection future.
Sourcepub fn on_receiving_result<F>(
self,
task: impl FnOnce(Result<T, Error>) -> F + 'static + Send,
) -> Result<(), Error>
pub fn on_receiving_result<F>( self, task: impl FnOnce(Result<T, Error>) -> F + 'static + Send, ) -> Result<(), Error>
Register an ordered callback, then publish the request.
Ordering is selected before publication, even when the connection runs
concurrently. See PreparedRequest for barrier limits and deadlock risks.
§Errors
Returns an error if the callback task cannot be registered, without publishing the request. Preparation and publication errors are delivered to the callback. Returning an error from the callback ends the connection.
Sourcepub fn on_receiving_ok_result<F>(
self,
responder: Responder<T>,
task: impl FnOnce(T, Responder<T>) -> F + 'static + Send,
) -> Result<(), Error>
pub fn on_receiving_ok_result<F>( self, responder: Responder<T>, task: impl FnOnce(T, Responder<T>) -> F + 'static + Send, ) -> Result<(), Error>
Register an ordered success callback, then publish the request.
Errors are forwarded to responder, as with
SentRequest::on_receiving_ok_result.
§Errors
Returns a task-registration error without publishing the request.
Preparation, publication, and response errors are forwarded to responder.
Returning an error from the callback ends the connection.
Sourcepub fn forward_response_to(self, responder: Responder<T>) -> Result<(), Error>where
T: JsonRpcResponse,
pub fn forward_response_to(self, responder: Responder<T>) -> Result<(), Error>where
T: JsonRpcResponse,
Register ordered response forwarding, then publish the request.
Cancellation and response errors propagate as with
SentRequest::forward_response_to.
§Errors
Returns a task-registration error without publishing the request.
Preparation, publication, and response errors are forwarded to responder.