Skip to content

Commit 073f245

Browse files
committed
run fetch in a separate thread
1 parent 9bc8118 commit 073f245

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

mdbook-goals/src/team.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,18 @@ impl TeamName {
107107

108108
fn fetch<T>(path: &str) -> anyhow::Result<T>
109109
where
110-
T: DeserializeOwned,
110+
T: DeserializeOwned + Send,
111111
{
112-
let url = format!("{}/{}", v1::BASE_URL, path);
113-
Ok(reqwest::blocking::get(&url)?.json()?)
112+
// Run this on another thread because it can create a tokio runtime
113+
// for the block reqwest API which makes tokio grouchy when that runtime is
114+
// dropped.
115+
std::thread::scope(|scope| {
116+
scope
117+
.spawn(|| {
118+
let url = format!("{}/{}", v1::BASE_URL, path);
119+
Ok(reqwest::blocking::get(&url)?.json()?)
120+
})
121+
.join()
122+
.unwrap()
123+
})
114124
}

0 commit comments

Comments
 (0)