11use crate :: pending_request:: { PendingRequest , RequestExt } ;
22use crate :: * ;
33
4+ // --- Async client type aliases ---
5+
6+ /// The sending half of the channel used to enqueue one or more requests from [`AsyncClient`].
7+ ///
8+ /// These requests are processed and forwarded to [`RequestTracker::track_request`] to be assigned an ID and serialized.
9+ pub type AsyncRequestSender = futures:: channel:: mpsc:: UnboundedSender < RawOneOrMany < PendingRequest > > ;
10+
11+ /// The error returned by [`AsyncClient::send_request`] when a request fails.
12+ ///
13+ /// This may occur if the server responds with an error, the request is canceled, or the client is shut down.
14+ pub type AsyncRequestError = crate :: request:: Error < AsyncRequestSendError > ;
15+
16+ /// The error that occurs when a request cannot be sent into the async request channel.
17+ ///
18+ /// This typically means the client's background task has shut down or the queue is disconnected.
19+ pub type AsyncRequestSendError = futures:: channel:: mpsc:: TrySendError < RawOneOrMany < PendingRequest > > ;
20+
21+ /// The receiving half of the internal event stream, returned to users of [`AsyncClient`].
22+ ///
23+ /// This yields all incoming [`Event`]s from the Electrum server, including notifications and responses.
24+ pub type AsyncEventReceiver = futures:: channel:: mpsc:: UnboundedReceiver < Event > ;
25+
26+ // --- Blocking client type aliases ---
27+
28+ /// Channel sender for sending blocking requests from [`BlockingClient`] to the write thread.
29+ pub type BlockingRequestSender = std:: sync:: mpsc:: Sender < RawOneOrMany < PendingRequest > > ;
30+
31+ /// Error returned by [`BlockingClient::send_request`] if the request fails or is canceled.
32+ pub type BlockingRequestError = crate :: request:: Error < BlockingRequestSendError > ;
33+
34+ /// Error that occurs when a blocking request cannot be sent to the internal request channel.
35+ ///
36+ /// Typically indicates that the client has been shut down.
37+ pub type BlockingRequestSendError = std:: sync:: mpsc:: SendError < RawOneOrMany < PendingRequest > > ;
38+
39+ /// Channel receiver used to receive [`Event`]s from the Electrum server.
40+ pub type BlockingEventReceiver = std:: sync:: mpsc:: Receiver < Event > ;
41+
442/// An asynchronous Electrum client built on the [`futures`] I/O ecosystem.
543///
644/// This client allows sending JSON-RPC requests and receiving [`Event`]s from an Electrum server
@@ -21,7 +59,7 @@ use crate::*;
2159/// [`Event`]: crate::Event
2260/// [`AsyncBufRead`]: futures::io::AsyncBufRead
2361/// [`AsyncWrite`]: futures::io::AsyncWrite
24- /// [`AsyncEventReceiver`]: crate::AsyncEventReceiver
62+ /// [`AsyncEventReceiver`]: crate::client:: AsyncEventReceiver
2563#[ derive( Debug , Clone ) ]
2664pub struct AsyncClient {
2765 tx : AsyncRequestSender ,
@@ -48,7 +86,7 @@ impl AsyncClient {
4886 /// - A `Future`: the client worker loop. This must be polled (e.g., via `tokio::spawn`)
4987 /// to drive the connection.
5088 ///
51- /// [`AsyncEventReceiver`]: crate::AsyncEventReceiver
89+ /// [`AsyncEventReceiver`]: crate::client:: AsyncEventReceiver
5290 /// [`Event`]: crate::Event
5391 pub fn new < R , W > (
5492 reader : R ,
@@ -116,7 +154,7 @@ impl AsyncClient {
116154 /// - A `Future`: the client worker loop. This must be spawned or polled to keep the client
117155 /// alive.
118156 ///
119- /// [`AsyncEventReceiver`]: crate::AsyncEventReceiver
157+ /// [`AsyncEventReceiver`]: crate::client:: AsyncEventReceiver
120158 /// [`Event`]: crate::Event
121159 /// [`AsyncClient::new`]: crate::AsyncClient::new
122160 #[ cfg( feature = "tokio" ) ]
@@ -179,7 +217,7 @@ impl AsyncClient {
179217 ///
180218 /// [`send_request`]: Self::send_request
181219 /// [`Event`]: crate::Event
182- /// [`AsyncEventReceiver`]: crate::AsyncEventReceiver
220+ /// [`AsyncEventReceiver`]: crate::client:: AsyncEventReceiver
183221 /// [`AsyncRequestSendError`]: crate::AsyncRequestSendError
184222 pub fn send_event_request < Req > ( & self , request : Req ) -> Result < ( ) , AsyncRequestSendError >
185223 where
@@ -209,7 +247,7 @@ impl AsyncClient {
209247 /// [`BatchRequest`]: crate::BatchRequest
210248 /// [`BatchRequest::request`]: crate::BatchRequest::request
211249 /// [`BatchRequest::event_request`]: crate::BatchRequest::event_request
212- /// [`AsyncEventReceiver`]: crate::AsyncEventReceiver
250+ /// [`AsyncEventReceiver`]: crate::client:: AsyncEventReceiver
213251 pub fn send_batch ( & self , batch_req : BatchRequest ) -> Result < bool , AsyncRequestSendError > {
214252 match batch_req. into_inner ( ) {
215253 Some ( batch) => self . tx . unbounded_send ( batch) . map ( |_| true ) ,
@@ -229,7 +267,7 @@ impl AsyncClient {
229267/// Use the associated [`BlockingEventReceiver`] to receive [`Event`]s emitted by the server.
230268///
231269/// [`Event`]: crate::Event
232- /// [`BlockingEventReceiver`]: crate::BlockingEventReceiver
270+ /// [`BlockingEventReceiver`]: crate::client:: BlockingEventReceiver
233271#[ derive( Debug , Clone ) ]
234272pub struct BlockingClient {
235273 tx : BlockingRequestSender ,
@@ -258,7 +296,7 @@ impl BlockingClient {
258296 /// used to monitor or explicitly join the background threads if desired.
259297 ///
260298 /// [`Event`]: crate::Event
261- /// [`BlockingEventReceiver`]: crate::BlockingEventReceiver
299+ /// [`BlockingEventReceiver`]: crate::client:: BlockingEventReceiver
262300 /// [`JoinHandle`]: std::thread::JoinHandle
263301 pub fn new < R , W > (
264302 reader : R ,
@@ -347,7 +385,7 @@ impl BlockingClient {
347385 /// Returns [`BlockingRequestSendError`] if the request could not be queued for sending.
348386 ///
349387 /// [`Event`]: crate::Event
350- /// [`BlockingEventReceiver`]: crate::BlockingEventReceiver
388+ /// [`BlockingEventReceiver`]: crate::client:: BlockingEventReceiver
351389 /// [`BlockingRequestSendError`]: crate::BlockingRequestSendError
352390 pub fn send_event_request < Req > ( & self , request : Req ) -> Result < ( ) , BlockingRequestSendError >
353391 where
@@ -377,7 +415,7 @@ impl BlockingClient {
377415 /// [`BatchRequest`]: crate::BatchRequest
378416 /// [`BatchRequest::request`]: crate::BatchRequest::request
379417 /// [`BatchRequest::event_request`]: crate::BatchRequest::event_request
380- /// [`BlockingEventReceiver`]: crate::BlockingEventReceiver
418+ /// [`BlockingEventReceiver`]: crate::client:: BlockingEventReceiver
381419 pub fn send_batch ( & self , batch_req : BatchRequest ) -> Result < bool , BlockingRequestSendError > {
382420 match batch_req. into_inner ( ) {
383421 Some ( batch) => self . tx . send ( batch) . map ( |_| true ) ,
0 commit comments