@@ -97,6 +97,7 @@ pub async fn submit_multiple_and_wait_verification(
9797 )
9898 . await ?;
9999
100+ // TODO maybe use a join to .await all at the same time, avoiding the loop
100101 for aligned_verification_data_item in aligned_verification_data. iter ( ) {
101102 await_batch_verification ( aligned_verification_data_item, eth_rpc_url, network) . await ?;
102103 }
@@ -305,11 +306,12 @@ async fn _submit_multiple(
305306
306307 let payment_service_addr = get_payment_service_address ( network) ;
307308
308- let sent_verification_data = {
309- // The sent verification data will be stored here so that we can calculate
310- // their commitments later.
309+ // TODO after i do the initial version, that sends all messages and then receives them. I will refactor it to use a tokio::select
310+ // So i can send and receive messages concurrently. This will allow to send infinite messages while receiving their responses
311+
312+ // Send messages
313+ let mut verification_data_commitments_rev = {
311314 send_messages (
312- response_stream. clone ( ) ,
313315 ws_write,
314316 payment_service_addr,
315317 verification_data,
@@ -320,26 +322,18 @@ async fn _submit_multiple(
320322 . await ?
321323 } ;
322324
323- let num_responses = Arc :: new ( Mutex :: new ( 0 ) ) ;
324-
325- // This vector is reversed so that when responses are received, the commitments corresponding
326- // to that response can simply be popped of this vector.
327- let mut verification_data_commitments_rev: Vec < VerificationDataCommitment > =
328- sent_verification_data
329- . into_iter ( )
330- . map ( |vd| vd. into ( ) )
331- . rev ( )
332- . collect ( ) ;
333-
325+ // Receive responses
334326 let aligned_verification_data = receive (
335327 response_stream,
336- ws_write_clone,
337328 verification_data. len ( ) ,
338- num_responses,
339329 & mut verification_data_commitments_rev,
340330 )
341331 . await ?;
342332
333+ // Close connection
334+ debug ! ( "Closing connection" ) ;
335+ ws_write_clone. lock ( ) . await . close ( ) . await ?; // no method named close?
336+
343337 Ok ( aligned_verification_data)
344338}
345339
0 commit comments