Skip to content

Commit

Permalink
I don't know
Browse files Browse the repository at this point in the history
  • Loading branch information
hatoo committed Jan 5, 2025
1 parent 40fe69b commit 8b09f9f
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,35 +1122,31 @@ pub async fn work2(
let report_tx = report_tx.clone();
let counter = counter.clone();
let client = client.clone();
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();

std::thread::spawn(move || {
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();

let futures = (0..num_connection)
.map(|_| {
let report_tx = report_tx.clone();
let counter = counter.clone();
let client = client.clone();
rt.spawn(async move {
let mut client_state = ClientStateHttp1::default();
while counter.fetch_add(1, Ordering::Relaxed) < n_tasks {
let res = client.work_http1(&mut client_state).await;
let is_cancel = is_cancel_error(&res);
report_tx.send_async(res).await.unwrap();
if is_cancel {
break;
}
let local = tokio::task::LocalSet::new();

(0..num_connection).for_each(|_| {
let report_tx = report_tx.clone();
let counter = counter.clone();
let client = client.clone();
local.spawn_local(async move {
let mut client_state = ClientStateHttp1::default();
while counter.fetch_add(1, Ordering::Relaxed) < n_tasks {
let res = client.work_http1(&mut client_state).await;
let is_cancel = is_cancel_error(&res);
report_tx.send_async(res).await.unwrap();
if is_cancel {
break;
}
})
})
.collect::<Vec<_>>();
rt.block_on(async {
for f in futures {
let _ = f.await;
}
}
});
});
rt.block_on(local);
})
})
.collect::<Vec<_>>();
Expand Down

0 comments on commit 8b09f9f

Please sign in to comment.