-
Notifications
You must be signed in to change notification settings - Fork 72
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
refactor: Streamline access shared utilities #108
Conversation
Won't this complicate the future standalone usage of the EventWriter? This is what I'm currently doing:
Now it looks like I need to do this:
Not a huge deal but I'm still interested in getting a rather simple convertor object for simple purposes and more complex confiugration only when it's needed. This works with the following patch:
Code sample: https://github.com/txpipe/oura/tree/pavlix-cip15 I'm sorry if the name of the branch doesn't fit your workflow, but it's not even really a feature branch at the moment, rather a scratch branch to keep the examples public. |
I'll take a look as soon as I start my day tomorrow. |
@pavlix thanks for the feedback. I wasn't taking into account that use-case, which I think makes a lot of sense. It could also be used for some blackbox testing of the mapper (putting a known block and expecting a known set of events). To address your concern, I've added the following constructor to the EventMapper: pub fn standalone(
output: StageSender,
well_known: Option<ChainWellKnownInfo>,
config: Config,
) -> Self {
let utils = Arc::new(Utils::new(well_known.unwrap_or_default()));
Self::new(output, utils, config)
} In this way, we could create a new one by calling |
@@ -95,6 +95,12 @@ impl FromStr for MagicArg { | |||
} | |||
} | |||
|
|||
impl Default for MagicArg { |
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.
awesome :)
//! | ||
//! This module includes general-purpose utilities that could potentially be | ||
//! used by more than a single stage. The entry point to this utilities is | ||
//! desgined as singelton [`Utils`] instance shared by all stages through an Arc |
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.
typo: designed
This looks good to me. Other than the typo I don't see any problems. I didn't request changes because that typo doesn't affect the code. I didn't press approve because I assume we're waiting for @pavlix to reply to your latest changes :). |
Merged in now, thank you all contributors! |
The utils module includes general-purpose utilities that could potentially be used by more than a single stage. Up to this point, access to the utilities was ad-hoc and internal to the code of each stage. This approach is suboptimal in terms of memory (excessive cloning) and prevents from implementing utilities that share a state between stages.
This PR introduces a new struct
Utils
that serves as an entry point that follows a singelton pattern, all stages share the same instance via anArc
pointer.This change affects the stage bootstrapping procedure, which resulted in a lot of changes throughout the codebase. Don't be alarmed, is mostly boilerplate.