@@ -1053,8 +1053,17 @@ async fn consume_events(
1053
1053
}
1054
1054
} ;
1055
1055
1056
- if sender. send( outcome. clone( ) ) . await . is_err( ) {
1057
- return Err ( SimulationError :: MpscChannelError ( format!( "Error sending simulation output {outcome:?}." ) ) ) ;
1056
+ select!{
1057
+ biased;
1058
+ _ = listener. clone( ) => {
1059
+ return Ok ( ( ) )
1060
+ }
1061
+ send_result = sender. send( outcome. clone( ) ) => {
1062
+ if send_result. is_err( ) {
1063
+ return Err ( SimulationError :: MpscChannelError (
1064
+ format!( "Error sending simulation output {outcome:?}." ) ) ) ;
1065
+ }
1066
+ }
1058
1067
}
1059
1068
}
1060
1069
}
@@ -1118,8 +1127,17 @@ async fn produce_events<N: DestinationGenerator + ?Sized, A: PaymentGenerator +
1118
1127
1119
1128
// Send the payment, exiting if we can no longer send to the consumer.
1120
1129
let event = SimulationEvent :: SendPayment ( destination. clone( ) , amount) ;
1121
- if sender. send( event. clone( ) ) . await . is_err( ) {
1122
- return Err ( SimulationError :: MpscChannelError ( format!( "Stopped activity producer for {amount}: {source} -> {destination}." ) ) ) ;
1130
+ select!{
1131
+ biased;
1132
+ _ = listener. clone( ) => {
1133
+ return Ok ( ( ) ) ;
1134
+ } ,
1135
+ send_result = sender. send( event. clone( ) ) => {
1136
+ if send_result. is_err( ) {
1137
+ return Err ( SimulationError :: MpscChannelError (
1138
+ format!( "Stopped activity producer for {amount}: {source} -> {destination}." ) ) ) ;
1139
+ }
1140
+ } ,
1123
1141
}
1124
1142
1125
1143
current_count += 1 ;
@@ -1314,10 +1332,18 @@ async fn produce_simulation_results(
1314
1332
}
1315
1333
} ,
1316
1334
SimulationOutput :: SendPaymentFailure ( payment, result) => {
1317
- if results. send( ( payment, result. clone( ) ) ) . await . is_err( ) {
1318
- break Err ( SimulationError :: MpscChannelError (
1319
- format!( "Failed to send payment result: {result} for payment {:?} dispatched at {:?}." , payment. hash, payment. dispatch_time) ,
1320
- ) ) ;
1335
+ select!{
1336
+ _ = listener. clone( ) => {
1337
+ return Ok ( ( ) ) ;
1338
+ } ,
1339
+ send_result = results. send( ( payment, result. clone( ) ) ) => {
1340
+ if send_result. is_err( ) {
1341
+ break Err ( SimulationError :: MpscChannelError (
1342
+ format!( "Failed to send payment result: {result} for payment {:?} dispatched at {:?}." ,
1343
+ payment. hash, payment. dispatch_time) ,
1344
+ ) ) ;
1345
+ }
1346
+ } ,
1321
1347
}
1322
1348
}
1323
1349
} ;
@@ -1384,7 +1410,8 @@ async fn track_payment_result(
1384
1410
} ,
1385
1411
send_payment_result = results. send( ( payment, res. clone( ) ) ) => {
1386
1412
if send_payment_result. is_err( ) {
1387
- return Err ( SimulationError :: MpscChannelError ( format!( "Failed to send payment result {res} for payment {payment}." ) ) )
1413
+ return Err ( SimulationError :: MpscChannelError (
1414
+ format!( "Failed to send payment result {res} for payment {payment}." ) ) )
1388
1415
}
1389
1416
}
1390
1417
}
0 commit comments