Skip to content

feat: Add Client::call_async - #59

Merged
tvpeter merged 2 commits into
bitcoindevkit:masterfrom
ValuedMammal:feat/call_async
Aug 27, 2026
Merged

tvpeter merged 2 commits into
bitcoindevkit:masterfrom
ValuedMammal:feat/call_async

Conversation

@ValuedMammal

@ValuedMammal ValuedMammal commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR adds Client::call_async, an async counterpart to the existing Client::call method. It mirrors the sync implementation, by building a JSON-RPC Request with an auto-incremented ID, invoking a caller-supplied send_fn to perform the transport, verifying the response ID matches the request ID, and deserializing the result into T, but accepts an AsyncFn(&Request) -> Result<Response, E> and awaits the response instead of calling a blocking closure. Since Client remains sans-io, this lets consumers plug in an async transport without needing a parallel async client type or duplicating request/response handling logic.

Notes to the reviewers

call_async's send_fn closure takes the jsonrpc::Request by reference (&Request) rather than by value like the sync call. This is for ergonomic reasons, as serializing to JSON using serde_json is typically non-consuming. Error handling, ID validation, and serialization logic are otherwise identical to call.

Changelog notice

  • Added Client::call_async for making JSON-RPC calls with an async send_fn transport.

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Comment thread src/client.rs Outdated

@tvpeter tvpeter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this.

The implementation is sound and good to go.

I left a nit.

Comment thread Cargo.toml Outdated
Comment on lines +25 to +26
bitreq = { version = "0.3.7", features = ["async"] }
tokio = { version = "1", features = ["full"] }

@ValuedMammal ValuedMammal Aug 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than pull in these dev-dependencies right now, we could add Client::call_async in a separate commit (23c6fd6) and leave the async example as a draft.

@ValuedMammal

ValuedMammal commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor Author

I may have figured out a cleaner solution to call_async by simplifying the send_fn at the callsite.

  • Still to do: Reword the commit and PR description (48901da) ✅

@ValuedMammal
ValuedMammal marked this pull request as ready for review August 24, 2026 18:40
Comment thread src/client.rs Outdated

@tvpeter tvpeter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 48901da

I left a non-blocking nit.

@tvpeter tvpeter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reACK 4a99a54

@tvpeter
tvpeter merged commit 87cfb90 into bitcoindevkit:master Aug 27, 2026
8 checks passed
@ValuedMammal
ValuedMammal deleted the feat/call_async branch August 27, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants