Struct AsyncBatchRequest

Source
pub struct AsyncBatchRequest { /* private fields */ }
Expand description

A builder for batching multiple asynchronous requests to the Electrum server.

This type allows queuing both:

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

Source

pub fn new() -> Self

Creates a new empty async batch request builder.

Source

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.

Source

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).

Source

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.

Trait Implementations§

Source§

impl Debug for AsyncBatchRequest

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for AsyncBatchRequest

Source§

fn default() -> AsyncBatchRequest

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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, 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.