Skip to content

Commit 489e497

Browse files
committed
Making the simulation results function always wait for tasks to finish
1 parent 4b6873f commit 489e497

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

sim-lib/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,11 +1184,11 @@ async fn produce_simulation_results(
11841184
) -> Result<(), SimulationError> {
11851185
let mut set = tokio::task::JoinSet::new();
11861186

1187-
loop {
1187+
let result = loop {
11881188
tokio::select! {
11891189
biased;
11901190
_ = listener.clone() => {
1191-
break;
1191+
break Ok(())
11921192
},
11931193
output = output_receiver.recv() => {
11941194
match output {
@@ -1200,31 +1200,32 @@ async fn produce_simulation_results(
12001200
source_node.clone(), results.clone(), payment, listener.clone()
12011201
));
12021202
} else {
1203-
return Err(SimulationError::MissingNodeError(format!("Source node with public key: {} unavailable.", payment.source)));
1203+
break Err(SimulationError::MissingNodeError(format!("Source node with public key: {} unavailable.", payment.source)));
12041204
}
12051205
},
12061206
SimulationOutput::SendPaymentFailure(payment, result) => {
12071207
if results.send((payment, result.clone())).await.is_err() {
1208-
return Err(SimulationError::MpscChannelError(
1208+
break Err(SimulationError::MpscChannelError(
12091209
format!("Failed to send payment result: {result} for payment {:?} dispatched at {:?}.", payment.hash, payment.dispatch_time),
12101210
));
12111211
}
12121212
}
12131213
};
12141214
},
1215-
None => return Ok(())
1215+
None => break Ok(())
12161216
}
12171217
}
12181218
}
1219-
}
1219+
};
12201220

12211221
log::debug!("Simulation results producer exiting.");
12221222
while let Some(res) = set.join_next().await {
12231223
if let Err(e) = res {
12241224
log::error!("Simulation results producer task exited with error: {e}.");
12251225
}
12261226
}
1227-
Ok(())
1227+
1228+
result
12281229
}
12291230

12301231
async fn track_payment_result(

0 commit comments

Comments
 (0)