pub struct AsyncBatchRequest { /* private fields */ }Expand description
A builder for batching multiple asynchronous requests to the Electrum server.
This type allows queuing both:
- tracked requests via
request(which return aFuturethat resolves to a response), and - event-style requests via
event_request(which emitEvents through theAsyncEventReceiverinstead of a future).
After building the batch, submit it using AsyncClient::send_batch. The batch will be
converted into a raw JSON-RPC message and sent to the server.
Important: Do not .await any futures returned by request until after the batch has
been sent. Doing so will cause the future to block indefinitely, as the request ID is not yet
assigned and the response cannot be matched.
This type is useful for reducing round-trips and issuing dependent or related requests together.
Implementations§
Source§impl AsyncBatchRequest
impl AsyncBatchRequest
Sourcepub fn into_inner(self) -> Option<MaybeBatch<AsyncPendingRequest>>
pub fn into_inner(self) -> Option<MaybeBatch<AsyncPendingRequest>>
Consumes the batch and returns its raw contents, if any requests were added.
Returns Some if the batch is non-empty, or None if it was empty.
This is used internally by AsyncClient::send_batch to extract the batched request set.
Sourcepub fn request<Req>(
&mut self,
req: Req,
) -> impl Future<Output = Result<Req::Response, BatchRequestError>> + Send + Sync + 'static
pub fn request<Req>( &mut self, req: Req, ) -> impl Future<Output = Result<Req::Response, BatchRequestError>> + Send + Sync + 'static
Adds a tracked request to the batch and returns a Future that resolves to the response.
This request will be tracked internally. The returned future must only be .awaited
after the batch has been submitted with AsyncClient::send_batch. Awaiting too early
will block forever.
§Errors
Returns an error if the request could not be added (e.g., duplicate or overflow).
Sourcepub fn event_request<Req>(&mut self, request: Req)
pub fn event_request<Req>(&mut self, request: Req)
Adds an event-style request to the batch.
These requests do not return a future and will not be tracked internally. Any server
response (including the initial result and any future notifications) will be delivered as
Events through the AsyncEventReceiver stream.
Use this for subscription-style RPCs where responses should be handled uniformly as events.