Skip to content

Commit

Permalink
Removed unnecessary async wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dadepo committed May 26, 2024
1 parent 3d2f42f commit 02ba07a
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ pub struct EndpointsConfig {
}

pub trait HttpClient {
fn send_request(&self, path: String) -> impl std::future::Future<Output = Result<Response, AppError>> + Send;
fn send_request(
&self,
path: String,
) -> impl std::future::Future<Output = Result<Response, AppError>> + Send;
}

impl HttpClient for reqwest::Client {
Expand Down Expand Up @@ -99,41 +102,38 @@ impl<C: HttpClient> CheckpointClient<C> {
)?;

let results = join_all(endpoints.iter().map(|endpoint| async {
async {
let path = format!(
"{}/eth/v1/beacon/states/{}/finality_checkpoints",
endpoint.clone(),
self.state_id
);
let result = self.client.send_request(path);
match result.await {
Ok(res) => {
if res.status().is_success() {
ResponsePayloadWithEndpointInfo {
payload: res
.json::<SuccessEndpointPayload>()
.await
.map_err(|e| AppError::EndpointResponseError(e.to_string())),
endpoint: endpoint.clone(),
}
} else {
ResponsePayloadWithEndpointInfo {
payload: Err(AppError::EndpointResponseError(format!(
"Error with calling {} status code {}",
endpoint.clone(),
res.status()
))),
endpoint: endpoint.clone(),
}
let path = format!(
"{}/eth/v1/beacon/states/{}/finality_checkpoints",
endpoint.clone(),
self.state_id
);
let result = self.client.send_request(path).await;
match result {
Ok(res) => {
if res.status().is_success() {
ResponsePayloadWithEndpointInfo {
payload: res
.json::<SuccessEndpointPayload>()
.await
.map_err(|e| AppError::EndpointResponseError(e.to_string())),
endpoint: endpoint.clone(),
}
} else {
ResponsePayloadWithEndpointInfo {
payload: Err(AppError::EndpointResponseError(format!(
"Error with calling {} status code {}",
endpoint.clone(),
res.status()
))),
endpoint: endpoint.clone(),
}
}
Err(e) => ResponsePayloadWithEndpointInfo {
payload: Err(e),
endpoint: endpoint.clone(),
},
}
Err(e) => ResponsePayloadWithEndpointInfo {
payload: Err(e),
endpoint: endpoint.clone(),
},
}
.await
}))
.await;

Expand Down

0 comments on commit 02ba07a

Please # to comment.