Skip to content

Commit 88bc36f

Browse files
committed
feat: new version with tokio join
1 parent b64bcb6 commit 88bc36f

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

batcher/aligned-sdk/src/sdk.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use sha3::{Digest, Keccak256};
3333
use std::{str::FromStr, sync::Arc};
3434
use tokio::{net::TcpStream, sync::Mutex};
3535
use tokio_tungstenite::{connect_async, tungstenite::Message, MaybeTlsStream, WebSocketStream};
36+
use tokio::sync::mpsc;
3637

3738
use log::{debug, info};
3839

@@ -305,35 +306,30 @@ async fn _submit_multiple(
305306

306307
let payment_service_addr = get_payment_service_address(network);
307308

308-
// TODO after i do the initial version, that sends all messages and then receives them. I will refactor it to use a tokio::select
309-
// So i can send and receive messages concurrently. This will allow to send infinite messages while receiving their responses
309+
let (sender_channel, receiver_channel) = mpsc::channel(1024); //TODO Magic number
310310

311-
// Send messages
312-
let mut verification_data_commitments_rev = {
311+
let (send_result, receive_result) = tokio::join!(
313312
send_messages(
314313
ws_write,
315314
payment_service_addr,
316315
verification_data,
317316
max_fees,
318317
wallet,
319318
nonce,
320-
)
321-
.await?
322-
};
323-
324-
// Receive responses
325-
let aligned_verification_data = receive(
326-
response_stream,
327-
verification_data.len(),
328-
&mut verification_data_commitments_rev,
329-
)
330-
.await?;
331-
319+
sender_channel,
320+
),
321+
receive(
322+
response_stream,
323+
receiver_channel
324+
),
325+
);
326+
332327
// Close connection
333-
debug!("Closing connection");
334-
ws_write_clone.lock().await.close().await?; // no method named close?
328+
info!("Closing WS connection");
329+
ws_write_clone.lock().await.close().await?;
335330

336-
Ok(aligned_verification_data)
331+
send_result?;
332+
return receive_result
337333
}
338334

339335
/// Submits a proof to the batcher to be verified in Aligned and waits for the verification on-chain.

0 commit comments

Comments
 (0)