-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
futures::join! two Futures from api #558
Comments
PS. extracting vars does not help too much. I doing lotsa requests for multiple accounts and Rust code operates 2 times slower than equivalent Nodejs code.. |
Your above example doesn't work becuase the use subxt::sp_core::crypto::AccountId32;
use futures::join;
use std::str::FromStr;
use subxt::{
PolkadotExtrinsicParams,
ClientBuilder,
DefaultConfig,
};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>>{
let api = ClientBuilder::new()
.set_url("wss://rpc.polkadot.io:443")
.build()
.await?
.to_runtime_api::<polkadot::RuntimeApi<DefaultConfig, PolkadotExtrinsicParams<DefaultConfig>>>();
let addr = AccountId32::from_str("13Ybj8CPEArUee78DxUAP9yX3ABmFNVQME1ZH4w8HVncHGzc").unwrap();
let staking = api.storage().staking();
let controller = staking.bonded(&addr, None);
let ledger = staking.ledger(&addr, None);
let (a, b) = join!(controller, ledger);
Ok(())
} We might be able to improve the ergonomics here by, instead of having fn bonded(&self, ...) -> impl Future<Item=Foo> + 'a {
let client = &self.client;
async move {
// take ownership of client, not all of self in the future, so that we dont rely on borrow,
// and put rest of generated logic in here.
}
} |
The above PR should make what you originally tried to do work (although note that you should use |
@jsdw thanks for clarification/example on usage. I can use features w/o any issues now. Thanks for spotting incorrect struct usage. This was taken from |
Ah you're right; I'll tweak the README to fix that error :) |
Trying to understand how to make parallel calls , just like I can do via polkadotjs/api via Promises.all()
What I get is the following:
I can extract staking and ledger as variables, but maybe I do something wrong? probably I do not understand the concept.
The text was updated successfully, but these errors were encountered: