From f0d14ae92b255e08c64234eea6ef5593ba254a67 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Wed, 20 Oct 2021 16:11:59 +0100 Subject: [PATCH] Create http api before adding the first torrent --- Cargo.lock | 2 +- crates/rqbit/Cargo.toml | 2 +- crates/rqbit/src/main.rs | 19 +++++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 78f4e15..56fa8d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1380,7 +1380,7 @@ dependencies = [ [[package]] name = "rqbit" -version = "1.1.1" +version = "1.1.2" dependencies = [ "anyhow", "clap", diff --git a/crates/rqbit/Cargo.toml b/crates/rqbit/Cargo.toml index 2b0e56d..2d156f2 100644 --- a/crates/rqbit/Cargo.toml +++ b/crates/rqbit/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rqbit" description = "A bittorent client" -version = "1.1.1" +version = "1.1.2" authors = ["Igor Katson "] edition = "2018" diff --git a/crates/rqbit/src/main.rs b/crates/rqbit/src/main.rs index 7c6d097..a563a57 100644 --- a/crates/rqbit/src/main.rs +++ b/crates/rqbit/src/main.rs @@ -163,6 +163,16 @@ async fn async_main(opts: Opts, spawner: BlockingSpawner) -> anyhow::Result<()> ..Default::default() }; + let http_api = { + let http_api = HttpApi::new(session.clone()); + spawn("HTTP API", { + let http_api_listen_addr = opts.http_api_listen_addr; + let http_api = http_api.clone(); + async move { http_api.make_http_api_and_run(http_api_listen_addr).await } + }); + http_api + }; + let handle = match session .add_torrent(opts.torrent_path, Some(torrent_opts)) .await @@ -172,14 +182,7 @@ async fn async_main(opts: Opts, spawner: BlockingSpawner) -> anyhow::Result<()> None => return Ok(()), }; - { - let http_api = HttpApi::new(session.clone()); - http_api.add_mgr(handle.clone()); - spawn("HTTP API", { - let http_api_listen_addr = opts.http_api_listen_addr; - async move { http_api.make_http_api_and_run(http_api_listen_addr).await } - }); - }; + http_api.add_mgr(handle.clone()); spawn("Stats printer", { let session = session.clone();