|
6 | 6 | api_client::{ApiClient, Observation}, |
7 | 7 | borsh::BorshDeserialize, |
8 | 8 | clap::Parser, |
| 9 | + futures::future::join_all, |
9 | 10 | posted_message::PostedMessageUnreliableData, |
10 | 11 | prost::Message, |
11 | 12 | secp256k1::{rand::rngs::OsRng, Secp256k1}, |
@@ -147,27 +148,27 @@ async fn run_listener<T: Signer + 'static>( |
147 | 148 | Err(_) => continue, |
148 | 149 | }; |
149 | 150 |
|
150 | | - input.api_clients.iter().for_each(|api_client| { |
151 | | - tokio::spawn({ |
152 | | - let (unreliable_data, api_client, signer) = ( |
153 | | - unreliable_data.clone(), |
154 | | - api_client.clone(), |
155 | | - input.signer.clone() |
156 | | - ); |
157 | | - async move { |
158 | | - let body = message_data_to_body(&unreliable_data); |
159 | | - match Observation::try_new(body.clone(), signer.clone()) { |
160 | | - Ok(observation) => { |
161 | | - if let Err(e) = api_client.post_observation(observation).await { |
162 | | - tracing::error!(url = api_client.get_base_url().to_string(), error = ?e, "Failed to post observation"); |
163 | | - } else { |
164 | | - tracing::info!(url = api_client.get_base_url().to_string(), "Observation posted successfully"); |
165 | | - }; |
166 | | - } |
167 | | - Err(e) => tracing::error!(error = ?e, "Failed to create observation"), |
| 151 | + tokio::spawn({ |
| 152 | + let (api_clients, signer) = (input.api_clients.clone(), input.signer.clone()); |
| 153 | + async move { |
| 154 | + let body = message_data_to_body(&unreliable_data); |
| 155 | + match Observation::try_new(body.clone(), signer.clone()) { |
| 156 | + Ok(observation) => { |
| 157 | + join_all(api_clients.iter().map(|api_client| { |
| 158 | + let observation = observation.clone(); |
| 159 | + let api_client = api_client.clone(); |
| 160 | + async move { |
| 161 | + if let Err(e) = api_client.post_observation(observation).await { |
| 162 | + tracing::error!(url = api_client.get_base_url().to_string(), error = ?e, "Failed to post observation"); |
| 163 | + } else { |
| 164 | + tracing::info!(url = api_client.get_base_url().to_string(), "Observation posted successfully"); |
| 165 | + } |
| 166 | + } |
| 167 | + })).await; |
168 | 168 | } |
| 169 | + Err(e) => tracing::error!(error = ?e, "Failed to create observation"), |
169 | 170 | } |
170 | | - }); |
| 171 | + } |
171 | 172 | }); |
172 | 173 | } |
173 | 174 |
|
|
0 commit comments