-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide async support for direct request/response communication #521
Conversation
let metadata_future = Self::get_metadata(&client); | ||
let runtime_version_future = Self::get_runtime_version(&client); | ||
|
||
let (genesis_hash, metadata, runtime_version) = futures::future::try_join3( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I'm not quite sure: On the one hand it's nice to actually take advantage of async by awaiting the futures in parallel. On the other hand the function is duplicated because there is a second implementation for the sync case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's fine. The async improvement is worth the small duplication.
src/lib.rs
Outdated
@@ -16,6 +16,7 @@ | |||
*/ | |||
#![cfg_attr(not(feature = "std"), no_std)] | |||
#![feature(error_in_core)] | |||
#![feature(async_fn_in_trait)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using async
in traits is not available on stable yet
@haerdib This is not finished yet, but can you have a first look?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the situation is for executor support in no_std. For example in wasm. I'm just wondering if we limit our potential use-cases by switching to async.
This would certainly need thorough investigation. But instead of switching completely to async, have you considered providing both, async and sync client? That would solve the question if it's available in wasm and such - if it's not, one can simply use the sync client.
Ofc, that would need quite some thought on how to provide two clients without having to duplicate everything.
It certainly would be nice if we can support both use cases sync and async without duplicating all the code. |
|
6add742
to
1260997
Compare
Still not finished but I think it is closer to what we want.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Examples compile without changes
Does that mean that this PR does not introduce any breaking changes? E.g. the users do not need to add the #[maybe_async::maybe_async(?Send)]
in case they use the good old sync variant?
Yes, at least it's my understanding that as long as we compile |
…h async and the other one sync
# Conflicts: # Cargo.lock # src/api/rpc_api/author.rs # src/api/rpc_api/chain.rs # src/api/rpc_api/events.rs # src/api/rpc_api/frame_system.rs # src/api/rpc_api/pallet_transaction_payment.rs # src/api/rpc_api/state.rs
# Conflicts: # src/api/rpc_api/chain.rs
I think this is now ready for merging. The nonce handling is now the same as before. |
@Niederb awesome new feature! is this stable? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely awesome, thanks a lot!
One thing: Could you rename the PR to a little more meaningful name and link the corresponding issue (though not close it I guess because Subscription is not yet async)
@@ -24,11 +24,13 @@ members = [ | |||
|
|||
[dependencies] | |||
# crates.io no_std | |||
async-trait = "0.1.68" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is a transitive dependency from maybe-async
and it does not compile without it. Dependencies for macros is a bit of a mystery for me...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Thanks for the explanation!
compose-macros/src/lib.rs
Outdated
$module: expr, | ||
$call: expr | ||
$(, $args: expr) *) => { | ||
{ | ||
use $crate::log::debug; | ||
use $crate::log::debug; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that indent correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I fixed it now. Seems cargo fmt
works differently in macros. Interesting
let metadata_future = Self::get_metadata(&client); | ||
let runtime_version_future = Self::get_runtime_version(&client); | ||
|
||
let (genesis_hash, metadata, runtime_version) = futures::future::try_join3( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's fine. The async improvement is worth the small duplication.
Co-authored-by: Bigna Härdi <73821294+haerdib@users.noreply.github.com>
@flipchan Thanks! I'm not quite sure what you mean by stable? I hope this PR will be merged very soon and then async will be available for the more simple communication that uses a single request/response (more complex communication based on subscriptions is not done yet). |
Done, but linking without closing is apparently not supported. See https://github.com/orgs/community/discussions/17308 |
My workaround for that was to simply add a link in the PR description. E.g. something like "related to #278". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
@@ -24,11 +24,13 @@ members = [ | |||
|
|||
[dependencies] | |||
# crates.io no_std | |||
async-trait = "0.1.68" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Thanks for the explanation!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot. Really nice!
request()
methodmaybe-async
crate to provide a sync and async API with little changes in the codedefault-features=false
now defaults to compiling the api in async modemaybe-async
is async