Reduce dependency on futures-util (#3358)

This commit is contained in:
Paolo Barbolini
2025-05-25 09:39:35 +02:00
committed by GitHub
parent d0aff24c85
commit 869ba86e51
32 changed files with 50 additions and 67 deletions
+3 -5
View File
@@ -10,10 +10,10 @@
//! websocket server and how the client-side and server-side code can be quite similar.
//!
use futures_util::stream::FuturesUnordered;
use futures_util::{SinkExt, StreamExt};
use std::ops::ControlFlow;
use std::time::Instant;
use tokio::task::JoinSet;
use tokio_tungstenite::tungstenite::Utf8Bytes;
// we will use tungstenite for websocket client impl (same library as what axum is using)
@@ -29,12 +29,10 @@ const SERVER: &str = "ws://127.0.0.1:3000/ws";
async fn main() {
let start_time = Instant::now();
//spawn several clients that will concurrently talk to the server
let mut clients = (0..N_CLIENTS)
.map(|cli| tokio::spawn(spawn_client(cli)))
.collect::<FuturesUnordered<_>>();
let mut clients = (0..N_CLIENTS).map(spawn_client).collect::<JoinSet<_>>();
//wait for all our clients to exit
while clients.next().await.is_some() {}
while clients.join_next().await.is_some() {}
let end_time = Instant::now();
+1 -1
View File
@@ -39,7 +39,7 @@ use axum::extract::connect_info::ConnectInfo;
use axum::extract::ws::CloseFrame;
//allows to split the websocket stream into separate TX and RX branches
use futures::{sink::SinkExt, stream::StreamExt};
use futures_util::{sink::SinkExt, stream::StreamExt};
#[tokio::main]
async fn main() {