Skip to content

Commit

Permalink
fix: store tokio runtime to avoid races when installing compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
gakonst committed Sep 13, 2021
1 parent f5ef809 commit f3f10a2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions dapp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::{
collections::{BTreeMap, HashMap},
path::{Path, PathBuf},
};
use tokio::runtime::Runtime;

/// Re-export of the Rust EVM for convenience
pub use evm;
Expand Down Expand Up @@ -310,6 +311,7 @@ struct SolcBuilder<'a> {
lib_paths: &'a [String],
versions: Vec<Version>,
releases: Vec<Version>,
runtime: Runtime,
}

use semver::{Version, VersionReq};
Expand All @@ -323,13 +325,15 @@ impl<'a> SolcBuilder<'a> {
lib_paths: &'a [String],
) -> Result<Self> {
let versions = svm::installed_versions().unwrap_or_default();
let releases = tokio::runtime::Runtime::new()?.block_on(svm::all_versions())?;
let runtime = tokio::runtime::Runtime::new()?;
let releases = runtime.block_on(svm::all_versions())?;
Ok(Self {
contracts,
remappings,
lib_paths,
versions,
releases,
runtime,
})
}

Expand Down Expand Up @@ -405,10 +409,7 @@ impl<'a> SolcBuilder<'a> {
.map(|version| {
println!("Installing {}", version);
// Blocking call to install it over RPC.
tokio::runtime::Runtime::new()
.unwrap()
.block_on(svm::install(&version))
.unwrap();
self.runtime.block_on(svm::install(&version)).unwrap();
dbg!(&self.versions);
self.versions.push(version.clone());
dbg!(&self.versions);
Expand Down

0 comments on commit f3f10a2

Please sign in to comment.