fixes related to recent tokio changes (#640)

This commit is contained in:
Yeastplume 2022-01-17 09:33:08 +00:00 committed by GitHub
parent 4c81e4a693
commit f5dbed2014
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View file

@ -319,7 +319,11 @@ impl Client {
if Handle::try_current().is_ok() {
let rt = RUNTIME.clone();
let client = self.clone();
std::thread::spawn(move || rt.lock().unwrap().block_on(client.send_request_async(req)))
std::thread::spawn(move || {
rt.lock()
.unwrap()
.block_on(async { client.send_request_async(req).await })
})
.join()
.unwrap()
} else {

View file

@ -230,6 +230,7 @@ impl NodeClient for HTTPNodeClient {
let url = format!("{}{}", self.node_url(), ENDPOINT);
let api_secret = self.node_api_secret();
let cl = self.client.clone();
let task = async move {
let params: Vec<_> = query_params
.chunks(chunk_size)
@ -243,7 +244,7 @@ impl NodeClient for HTTPNodeClient {
let mut tasks = Vec::with_capacity(params.len());
for req in &reqs {
tasks.push(self.client.post_async::<Request, Response>(
tasks.push(cl.post_async::<Request, Response>(
url.as_str(),
req,
api_secret.clone(),
@ -254,7 +255,11 @@ impl NodeClient for HTTPNodeClient {
task.try_collect().await
};
let res: Result<Vec<_>, _> = RUNTIME.lock().unwrap().block_on(task);
let rt = RUNTIME.clone();
let res: Result<Vec<_>, _> =
std::thread::spawn(move || rt.lock().unwrap().block_on(async move { task.await }))
.join()
.unwrap();
let results: Vec<OutputPrintable> = match res {
Ok(resps) => {