Skip to content

Commit

Permalink
Fix owner API scan (#591)
Browse files Browse the repository at this point in the history
Co-authored-by: jaspervdm <j@sper.dev>
  • Loading branch information
quentinlesceller and jaspervdm committed Mar 5, 2021
1 parent 594f4cc commit 6871185
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions impls/src/node_clients/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use futures::stream::FuturesUnordered;
use futures::TryStreamExt;
use std::collections::HashMap;
use std::env;
use tokio::runtime::Handle;

use crate::client_utils::{Client, RUNTIME};
use crate::libwallet;
Expand Down Expand Up @@ -222,7 +223,7 @@ impl NodeClient for HTTPNodeClient {
trace!("Output query chunk size is: {}", chunk_size);

let url = format!("{}{}", self.node_url(), ENDPOINT);

let api_secret = self.node_api_secret();
let task = async move {
let client = Client::new();

Expand All @@ -241,15 +242,22 @@ impl NodeClient for HTTPNodeClient {
tasks.push(client.post_async::<Request, Response>(
url.as_str(),
req,
self.node_api_secret(),
api_secret.clone(),
));
}

let task: FuturesUnordered<_> = tasks.into_iter().collect();
task.try_collect().await
};

let res: Result<Vec<Response>, _> = RUNTIME.lock().unwrap().block_on(task);
let res: Result<Vec<Response>, _> = if Handle::try_current().is_ok() {
let rt = RUNTIME.clone();
std::thread::spawn(move || rt.lock().unwrap().block_on(task))
.join()
.unwrap()
} else {
RUNTIME.lock().unwrap().block_on(task)
};

let results: Vec<OutputPrintable> = match res {
Ok(resps) => {
Expand Down

0 comments on commit 6871185

Please sign in to comment.