Skip to content

Commit 730b529

Browse files
committed
I don't know
1 parent 2604c2e commit 730b529

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

src/client.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,35 +1122,31 @@ pub async fn work2(
11221122
let report_tx = report_tx.clone();
11231123
let counter = counter.clone();
11241124
let client = client.clone();
1125+
let rt = tokio::runtime::Builder::new_current_thread()
1126+
.enable_all()
1127+
.build()
1128+
.unwrap();
1129+
11251130
std::thread::spawn(move || {
1126-
let rt = tokio::runtime::Builder::new_current_thread()
1127-
.enable_all()
1128-
.build()
1129-
.unwrap();
1130-
1131-
let futures = (0..num_connection)
1132-
.map(|_| {
1133-
let report_tx = report_tx.clone();
1134-
let counter = counter.clone();
1135-
let client = client.clone();
1136-
rt.spawn(async move {
1137-
let mut client_state = ClientStateHttp1::default();
1138-
while counter.fetch_add(1, Ordering::Relaxed) < n_tasks {
1139-
let res = client.work_http1(&mut client_state).await;
1140-
let is_cancel = is_cancel_error(&res);
1141-
report_tx.send_async(res).await.unwrap();
1142-
if is_cancel {
1143-
break;
1144-
}
1131+
let local = tokio::task::LocalSet::new();
1132+
1133+
(0..num_connection).for_each(|_| {
1134+
let report_tx = report_tx.clone();
1135+
let counter = counter.clone();
1136+
let client = client.clone();
1137+
local.spawn_local(async move {
1138+
let mut client_state = ClientStateHttp1::default();
1139+
while counter.fetch_add(1, Ordering::Relaxed) < n_tasks {
1140+
let res = client.work_http1(&mut client_state).await;
1141+
let is_cancel = is_cancel_error(&res);
1142+
report_tx.send_async(res).await.unwrap();
1143+
if is_cancel {
1144+
break;
11451145
}
1146-
})
1147-
})
1148-
.collect::<Vec<_>>();
1149-
rt.block_on(async {
1150-
for f in futures {
1151-
let _ = f.await;
1152-
}
1146+
}
1147+
});
11531148
});
1149+
rt.block_on(local);
11541150
})
11551151
})
11561152
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)