Fix jobserver_client: Create it as early as possible

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-07-19 12:15:00 +10:00
parent 2bf7640729
commit 67ca36a0b5
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -171,10 +171,16 @@ impl Termination for MainExit {
} }
fn main() -> MainExit { fn main() -> MainExit {
// Create jobserver client
let jobserver_client = match create_jobserver_client() {
Ok(jobserver_client) => jobserver_client,
Err(binstall_err) => return MainExit::Error(binstall_err),
};
let start = Instant::now(); let start = Instant::now();
let rt = Runtime::new().unwrap(); let rt = Runtime::new().unwrap();
let handle = rt.spawn(entry()); let handle = rt.spawn(entry(jobserver_client));
let result = rt.block_on(handle); let result = rt.block_on(handle);
drop(rt); drop(rt);
@ -190,7 +196,7 @@ fn main() -> MainExit {
}) })
} }
async fn entry() -> Result<()> { async fn entry(jobserver_client: jobserver::Client) -> Result<()> {
// Filter extraneous arg when invoked by cargo // Filter extraneous arg when invoked by cargo
// `cargo run -- --help` gives ["target/debug/cargo-binstall", "--help"] // `cargo run -- --help` gives ["target/debug/cargo-binstall", "--help"]
// `cargo binstall --help` gives ["/home/ryan/.cargo/bin/cargo-binstall", "binstall", "--help"] // `cargo binstall --help` gives ["/home/ryan/.cargo/bin/cargo-binstall", "binstall", "--help"]
@ -209,9 +215,6 @@ async fn entry() -> Result<()> {
let crate_names = take(&mut opts.crate_names); let crate_names = take(&mut opts.crate_names);
let opts = Arc::new(opts); let opts = Arc::new(opts);
// Create jobserver client
let jobserver_client = create_jobserver_client()?;
// Initialize reqwest client // Initialize reqwest client
let client = create_reqwest_client(opts.secure, opts.min_tls_version.map(|v| v.into()))?; let client = create_reqwest_client(opts.secure, opts.min_tls_version.map(|v| v.into()))?;