Skip to content

Commit ab4fcb1

Browse files
committed
Merge #10: refactor!: Unify PendingRequest and clean up API
d9521fe refactor!: Move client type aliases into client module (志宇) 0f4c565 refactor!: Clean up API naming, remove dead code, and restructure modules (志宇) 4509768 feat!: Unify PendingRequest via closure-based type erasure (志宇) Pull request description: ## Summary Eliminate duplicated `AsyncPendingRequest`/`BlockingPendingRequest` 21-variant enums and clean up the public API. ### Type erasure (`4509768`) Replace the two parallel pending request enums with a single `PendingRequest` struct that uses a `Box<dyn FnOnce + Send + Sync>` handler for closure-based type erasure. This: - Makes `RequestTracker` (formerly `State`) non-generic - Collapses `AsyncBatchRequest`/`BlockingBatchRequest` into a single `BatchRequest` - Removes all async/blocking-specific type aliases for response channels - Adds `BatchRequest::request_async()` and `request_blocking()` convenience methods that create channels internally and return receivers ### Naming and module cleanup (`0f4c565`) - **Type renames**: `State` → `RequestTracker`, `SatisfiedRequest` → `CompletedRequest`, `ErroredRequest` → `FailedRequest`, `RawNotificationOrResponse` → `RawIncoming`, `MaybeBatch` → `RawOneOrMany` - **Method renames**: `process_incoming` → `handle_incoming`, `into_satisfied` → `into_completed`, `into_errored` → `into_failed` - **Dead code removed**: `BatchRequestError` (no longer referenced after the type erasure refactor) - **Module restructure**: merged `batch_request.rs` into `pending_request.rs`, extracted wire types from `lib.rs` into `protocol.rs`, renamed `state.rs` → `request_tracker.rs` ### Client module separation (`d9521fe`) - Moved async/blocking type aliases from `lib.rs` into `client` module - Deleted 4 unused aliases: `AsyncEventSender`, `AsyncRequestReceiver`, `BlockingRequestReceiver`, `BlockingEventSender` - `client` is now `pub mod` — non-re-exported types available via `electrum_streaming_client::client::*` - Only `AsyncClient`, `BlockingClient`, and their error types are re-exported at the crate root ## Breaking changes - All renamed types and methods listed above - `AsyncBatchRequest` / `BlockingBatchRequest` replaced by unified `BatchRequest` - `AsyncPendingRequest` / `BlockingPendingRequest` replaced by unified `PendingRequest` - `State` is now `RequestTracker` and is no longer generic - `AsyncRequestSender`, `AsyncEventReceiver`, `BlockingRequestSender`, `BlockingEventReceiver` moved from crate root to `client` module ACKs for top commit: evanlinjin: self-ACK d9521fe Tree-SHA512: f99268135aab474befe2a866a5fd9ef067c2bb3d8aef6f14ccc49abbfb79aadd1669cb340563abe159293c7d0976138a76ed962d28af3ff09b546b8f94f721a3
2 parents d384cf2 + d9521fe commit ab4fcb1

9 files changed

Lines changed: 570 additions & 856 deletions

File tree

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ models.
1010

1111
- **Streaming protocol support**: Handles both server-initiated notifications and responses.
1212
- **Transport agnostic**: Works with any I/O type implementing the appropriate `Read`/`Write` traits.
13-
- **Sans-IO core**: The [`State`] struct tracks pending requests and processes server messages.
13+
- **Sans-IO core**: The [`RequestTracker`] struct tracks pending requests and handles incoming server messages.
1414
- **Typed request/response system**: Strongly typed Electrum method wrappers with minimal overhead.
1515

1616
## Example (async with Tokio)
1717

1818
```rust,no_run
19-
use electrum_streaming_client::{AsyncClient, AsyncBatchRequest, Event};
19+
use electrum_streaming_client::{AsyncClient, Event};
2020
use tokio::net::TcpStream;
2121
use futures::StreamExt;
2222
@@ -28,11 +28,7 @@ async fn main() -> anyhow::Result<()> {
2828
2929
tokio::spawn(worker); // spawn the client worker task
3030
31-
let mut batch = AsyncBatchRequest::new();
32-
let fut = batch.request(electrum_streaming_client::request::RelayFee);
33-
client.send_batch(batch)?;
34-
let relay_fee = fut.await?;
35-
31+
let relay_fee = client.send_request(electrum_streaming_client::request::RelayFee).await?;
3632
println!("Relay fee: {relay_fee:?}");
3733
3834
while let Some(event) = events.next().await {

src/batch_request.rs

Lines changed: 0 additions & 209 deletions
This file was deleted.

0 commit comments

Comments
 (0)