Skip to content
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 an async example #551

Merged
merged 12 commits into from
May 2, 2023
Merged

Provide an async example #551

merged 12 commits into from
May 2, 2023

Conversation

Niederb
Copy link
Contributor

@Niederb Niederb commented Apr 26, 2023

  • Basically a modify the get_blocks example such that it takes advantage of async by awaiting multiple futures at the same time.
  • Renamed the example to get_blocks_async
  • Also integrated it into the CI with a separate compilation and upload step.

@Niederb Niederb linked an issue Apr 26, 2023 that may be closed by this pull request
@Niederb Niederb marked this pull request as ready for review April 26, 2023 08:34
limitations under the License.
*/

//! Very simple example that shows how to fetch chain metadata with async.
Copy link
Contributor

Choose a reason for hiding this comment

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

metadata?

Copy link
Contributor

@echevrier echevrier Apr 26, 2023

Choose a reason for hiding this comment

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

In get_block.rs, the example description is also about metadata. ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I took this from the other example. It might be confusing because metadata has a special meaning in the polkadot eco-system. How about just using chain information in both examples?

Copy link
Contributor

Choose a reason for hiding this comment

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

Works for me 👍

@@ -27,6 +28,7 @@ use substrate_api_client::{
#[tokio::main]
async fn main() {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think: Do we still need the sync variant of get_blocks? We have different sync examples and the difference between sync and async is not that big.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initially I thought it would be nice to show that the async version is faster. Unfortunately that's not really the case. The sync has the small advantage of outputting something directly after each getter, so if something fails later on there is at least the output of the previous stuff.

@Niederb
Copy link
Contributor Author

Niederb commented Apr 27, 2023

  • Fixed the metadata comment as discussed
  • Removed the sync version of get_blocks
    • Integrated the async version instead in the CI. This needs a separate compilation and update step.
    • Added the synchronous subscription part to the async example such that is still there for reference and testing.

@Niederb Niederb requested a review from haerdib April 27, 2023 13:30
Copy link
Contributor

@haerdib haerdib left a 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 last wish: Could you update the PR description? 😇

@haerdib haerdib added the Z3-example Add or fix an example label Apr 28, 2023
@Niederb
Copy link
Contributor Author

Niederb commented Apr 28, 2023

Absolutely awesome, thanks a lot! One last wish: Could you update the PR description? 😇

Done

@Niederb Niederb merged commit e1c766c into master May 2, 2023
@Niederb Niederb deleted the tn/async-example branch July 17, 2023 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E1-breaksnothing Z3-example Add or fix an example
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide an example for async requests
3 participants