Skip to content

Commit

Permalink
refactor: improve callback type
Browse files Browse the repository at this point in the history
  • Loading branch information
evilrobot-01 committed Apr 29, 2024
1 parent c16d54c commit 162b178
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/pop-cli/src/commands/up/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl ZombienetCommand {
let spinner = multi.add(cliclack::spinner());
for attempt in (0..=1).rev() {
if let Err(e) =
binary.source(&cache, &mut |status| spinner.start(format(status))).await
binary.source(&cache, &|status| spinner.start(format(status))).await
{
match attempt {
0 => {
Expand Down
16 changes: 6 additions & 10 deletions crates/pop-parachains/src/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,7 @@ pub struct Binary {
}

impl Binary {
pub async fn source(
&self,
cache: &PathBuf,
callback: &mut impl FnMut(&str),
) -> Result<(), Error> {
pub async fn source(&self, cache: &PathBuf, callback: &impl Fn(&str)) -> Result<(), Error> {
for source in &self.sources {
source.process(cache, callback).await?;
}
Expand Down Expand Up @@ -430,7 +426,7 @@ impl Source {
path: &Path,
package: &str,
names: impl Iterator<Item = (&'b String, PathBuf)>,
callback: &mut impl FnMut(&str),
callback: impl Fn(&str),
) -> Result<(), Error> {
// Build binaries and then copy to cache and target
let reader = cmd("cargo", vec!["build", "--release", "-p", package])
Expand Down Expand Up @@ -462,7 +458,7 @@ impl Source {
pub async fn process(
&self,
cache: &Path,
callback: &mut impl FnMut(&str),
callback: impl Fn(&str),
) -> Result<Option<Vec<PathBuf>>, Error> {
// Download or clone and build from source
match self {
Expand Down Expand Up @@ -820,7 +816,7 @@ mod tests {
.await?;
let missing_binaries = zombienet.missing_binaries();
for binary in missing_binaries {
binary.source(&cache).await?;
binary.source(&cache, &|_| {}).await?;
}

let spawn = zombienet.spawn().await;
Expand Down Expand Up @@ -859,7 +855,7 @@ mod tests {
version: TESTING_POLKADOT_VERSION.to_string(),
url: "https://github.com/paritytech/polkadot-sdk/releases/download/polkadot-v1.7.0/polkadot".to_string()
};
let result = source.process(&cache, &mut |_| {}).await;
let result = source.process(&cache, |_| {}).await;
assert!(result.is_ok());
assert!(temp_dir.path().join(POLKADOT_BINARY).exists());

Expand All @@ -885,7 +881,7 @@ mod tests {
version: Some(version),
};

let result = source.process(&cache).await;
let result = source.process(&cache, |_| {}).await;
assert!(result.is_ok());
assert!(temp_dir.path().join(POLKADOT_BINARY).exists());

Expand Down

0 comments on commit 162b178

Please sign in to comment.