feat: Add Client::call_async - #59
Draft
ValuedMammal wants to merge 2 commits into
Draft
Conversation
ValuedMammal
force-pushed
the
feat/call_async
branch
from
July 10, 2026 14:36
322e6b5 to
c0cfa04
Compare
tvpeter
reviewed
Jul 28, 2026
| Ok(response.result()?) | ||
| } | ||
|
|
||
| /// Execute the RPC asynchronously. |
Collaborator
There was a problem hiding this comment.
nit: I think it'll be great to expand the documentation for this fn too. Thank you
tvpeter
reviewed
Jul 28, 2026
tvpeter
left a comment
Collaborator
There was a problem hiding this comment.
Thank you for working on this.
The implementation is sound and good to go.
I left a nit.
ValuedMammal
commented
Aug 5, 2026
Comment on lines
+25
to
+26
| bitreq = { version = "0.3.7", features = ["async"] } | ||
| tokio = { version = "1", features = ["full"] } |
Contributor
Author
There was a problem hiding this comment.
Rather than pull in these dev-dependencies right now, we could add Client::call_async in a separate commit and leave the async example as a draft.
(dev) deps: Add `bitreq` 0.3.7 with `async` feature (dev) deps: Add `tokio` v1 with `full` feature
ValuedMammal
force-pushed
the
feat/call_async
branch
from
August 5, 2026 14:43
b1daa05 to
4efcfab
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
Client::call_async— an async counterpart toClient::callfor use with async transports.The method accepts a
send_fn: AsyncFn(Value) -> Result<Response, E>closure rather than passing theRequestdirectly to the transport. Internally,call_asyncbuilds the request, serializes the request to an ownedserde_json::Value, calls thesend_fn, and deserializes the response like the sync path.A working example is included in call_async.rs using
bitreq::send_async()frombitreq's async feature.Notes to the reviewers
Why
AsyncFn(Value) -> Result<Response, E>instead of passingRequest<'_>to the transport?The natural design would mirror the sync API:
F: for<'r> AsyncFn(Request<'r>) -> Result<Response, E>. This was explored but seems to hit a Rust language limitation. An async closureasync |req| transport.send_request(req).awaitthat captures a reference cannot satisfyfor<'r> AsyncFn(Request<'r>), as the closure ties the future's lifetime to both the transport reference and the request lifetime, so the bound is never satisfied. Passing an ownedValuebreaks the lifetime chain entirely.The tradeoff is that callers cannot use
BitreqHttpTransport::send_requestdirectly (its return type is tied to the borrow ofselfvia aBoxFuture). Thebitreq::post()free function shown in the example is a workaround that avoids that issue. Another alternative is to support the async flavor ofTransportalongside the currentbitreqclient module, but this would lead to duplicating the API which is precisely what the sans-io design is meant to avoid.Changelog notice
Added
Client::call_async: async RPC method acceptingAsyncFn(Value) -> Result<Response, E>for use with async transports