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

archive: Refactor archive_storage method into subscription #6483

Draft
wants to merge 10 commits into
base: lexnv/storage-diff
Choose a base branch
from

Conversation

lexnv
Copy link
Contributor

@lexnv lexnv commented Nov 14, 2024

This PR adapts the archive_storage implementation from a method to a subscription.

This keeps the archive APIs uniform and consistent.

Builds on: #5997

cc @paritytech/subxt-team

@lexnv lexnv added R0-silent Changes should not be mentioned in any release notes I4-refactor Code needs refactoring. I5-enhancement An additional feature request. labels Nov 14, 2024
@lexnv lexnv self-assigned this Nov 14, 2024

/// Sends all the events to the sink.
async fn process_storage_events(rx: &mut mpsc::Receiver<QueryResult>, sink: &mut Subscription) {
while let Some(event) = rx.recv().await {
Copy link
Member

@niklasad1 niklasad1 Nov 14, 2024

Choose a reason for hiding this comment

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

perhaps do a select loop here instead to terminate this when the subscription is closed, just to be on the safe side if the connection gets idle after getting being backpressured and no events are emitted....

    loop {
        tokio::select! {
        _ = sink.closed() => return,
        event = rx.recv() => { // code to read the event here }
        }
    }

@@ -57,42 +59,12 @@ use tokio::sync::mpsc;

pub(crate) const LOG_TARGET: &str = "rpc-spec-v2::archive";

/// The configuration of [`Archive`].
Copy link
Member

Choose a reason for hiding this comment

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

woo 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I4-refactor Code needs refactoring. I5-enhancement An additional feature request. R0-silent Changes should not be mentioned in any release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants