Skip to content

Commit

Permalink
SQUASH-ME or DELETE-ME
Browse files Browse the repository at this point in the history
  • Loading branch information
sr-gi committed Oct 20, 2023
1 parent 255ea00 commit acce1e1
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions sim-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,49 +893,49 @@ async fn write_payment_results(
print_batch_size: u32,
no_results: bool,
) -> Result<(), SimulationError> {
let mut writer = if no_results {
WriterBuilder::new().from_path("/dev/null")?
} else {
WriterBuilder::new().from_path(format!(
let mut writer = if !no_results {
Some(WriterBuilder::new().from_path(format!(
"simulation_{:?}.csv",
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs()
))?
))?)
} else {
None
};

let mut result_logger = PaymentResultLogger::new();

let mut counter = 1;
let mut counter = 0;
loop {
tokio::select! {
biased;
_ = listener.clone() => {
log::debug!("Simulation results consumer received shutdown signal.");
break writer.flush().map_err(|_| SimulationError::FileError)
return writer.map(|ref mut w| w.flush().map_err(|_| SimulationError::FileError)).unwrap_or(Ok(()));

},
payment_report = receiver.recv() => {
match payment_report {
Some((details, result)) => {
result_logger.report_result(&details, &result);
log::trace!("Resolved dispatched payment: {} with: {}.", details, result);

writer.serialize((details, result)).map_err(|e| {
let _ = writer.flush();
SimulationError::CsvError(e)
})?;
if let Some(ref mut w) = writer {
w.serialize((details, result)).map_err(|e| {
let _ = w.flush();
SimulationError::CsvError(e)
})?;

if print_batch_size == counter {
writer.flush().map_err(|_| SimulationError::FileError)?;
counter = 1;
} else {
counter += 1;
counter = counter % print_batch_size + 1;
if print_batch_size == counter {
w.flush().map_err(|_| SimulationError::FileError)?;
}
}
continue;
},
None => {
break writer.flush().map_err(|_| SimulationError::FileError)
return writer.map(|ref mut w| w.flush().map_err(|_| SimulationError::FileError)).unwrap_or(Ok(()));

}
}
}
Expand Down

0 comments on commit acce1e1

Please sign in to comment.