Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit f804310

Browse files
authored
Merge pull request #231 from alexcrichton/refactor-spawn
Refactor spawning in wasi crates
2 parents 275499c + 71e1685 commit f804310

File tree

4 files changed

+219
-160
lines changed

4 files changed

+219
-160
lines changed

crates/wasi-http/src/p3/host/handler.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tokio::sync::mpsc;
1818
use tokio::sync::oneshot;
1919
use tracing::debug;
2020
use wasmtime::component::{Accessor, AccessorTask, Resource};
21-
use wasmtime_wasi::p3::{AbortOnDropHandle, AccessorTaskFn, ResourceView as _};
21+
use wasmtime_wasi::p3::{AbortOnDropHandle, ResourceView as _, SpawnExt};
2222

2323
struct TrailerTask {
2424
rx: OutgoingTrailerFuture,
@@ -131,11 +131,11 @@ where
131131
content_length: Some(ContentLength { limit, sent }),
132132
..
133133
} if limit != sent => {
134-
store.spawn(AccessorTaskFn(move |_: &Accessor<U, Self>| async move {
134+
store.spawn_fn(move |_| async move {
135135
tx.write(Err(ErrorCode::HttpRequestBodySize(Some(sent))))
136136
.await;
137137
Ok(())
138-
}));
138+
});
139139
return Ok(Err(ErrorCode::HttpRequestBodySize(Some(sent))));
140140
}
141141
Body::Guest {
@@ -149,11 +149,11 @@ where
149149
let request = http::Request::from_parts(request, body);
150150
match client.send_request(request, options).await? {
151151
Ok((response, io)) => {
152-
store.spawn(AccessorTaskFn(|_: &Accessor<U, Self>| async {
152+
store.spawn_fn(|_| async {
153153
let res = io.await;
154154
tx.write(res.map_err(Into::into)).await;
155155
Ok(())
156-
}));
156+
});
157157
match response.await {
158158
Ok(response) => response.map(|body| body.map_err(Into::into).boxed()),
159159
Err(err) => return Ok(Err(err)),
@@ -177,11 +177,11 @@ where
177177
let request = http::Request::from_parts(request, body);
178178
match client.send_request(request, options).await? {
179179
Ok((response, io)) => {
180-
store.spawn(AccessorTaskFn(|_: &Accessor<U, Self>| async {
180+
store.spawn_fn(|_| async {
181181
let res = io.await;
182182
tx.write(res.map_err(Into::into)).await;
183183
Ok(())
184-
}));
184+
});
185185
match response.await {
186186
Ok(response) => response.map(|body| body.map_err(Into::into).boxed()),
187187
Err(err) => return Ok(Err(err)),
@@ -197,12 +197,12 @@ where
197197
tx,
198198
content_length: None,
199199
} => {
200-
store.spawn({
200+
store.spawn_fn({
201201
let err = err.clone();
202-
AccessorTaskFn(move |_: &Accessor<U, Self>| async move {
202+
move |_| async move {
203203
tx.write(Err(err)).await;
204204
Ok(())
205-
})
205+
}
206206
});
207207
return Ok(Err(err));
208208
}
@@ -223,11 +223,11 @@ where
223223
let request = http::Request::from_parts(request, body);
224224
match client.send_request(request, options).await? {
225225
Ok((response, io)) => {
226-
store.spawn(AccessorTaskFn(|_: &Accessor<U, Self>| async {
226+
store.spawn_fn(|_| async {
227227
let res = io.await;
228228
tx.write(res.map_err(Into::into)).await;
229229
Ok(())
230-
}));
230+
});
231231
match response.await {
232232
Ok(response) => response.map(|body| body.map_err(Into::into).boxed()),
233233
Err(err) => return Ok(Err(err)),
@@ -262,7 +262,7 @@ where
262262
Ok(pair) => pair,
263263
Err(err) => return Ok(Err(err)),
264264
};
265-
store.spawn(AccessorTaskFn(move |_: &Accessor<U, Self>| async move {
265+
store.spawn_fn(move |_| async move {
266266
let (io_res, body_res) = futures::join! {
267267
io,
268268
async {
@@ -291,7 +291,7 @@ where
291291
let _ = body_res;
292292
tx.write(io_res.map_err(Into::into)).await;
293293
Ok(())
294-
}));
294+
});
295295
match response.await {
296296
Ok(response) => response.map(|body| body.map_err(Into::into).boxed()),
297297
Err(err) => return Ok(Err(err)),
@@ -306,10 +306,10 @@ where
306306
let request = http::Request::from_parts(request, body);
307307
match client.send_request(request, options).await? {
308308
Ok((response, io)) => {
309-
store.spawn(AccessorTaskFn(|_: &Accessor<U, Self>| async {
309+
store.spawn_fn(|_| async {
310310
_ = io.await;
311311
Ok(())
312-
}));
312+
});
313313
match response.await {
314314
Ok(response) => response.map(|body| body.map_err(Into::into).boxed()),
315315
Err(err) => return Ok(Err(err)),
@@ -327,10 +327,10 @@ where
327327
let request = http::Request::from_parts(request, body);
328328
match client.send_request(request, options).await? {
329329
Ok((response, io)) => {
330-
store.spawn(AccessorTaskFn(|_: &Accessor<U, Self>| async {
330+
store.spawn_fn(|_| async {
331331
_ = io.await;
332332
Ok(())
333-
}));
333+
});
334334
match response.await {
335335
Ok(response) => response.map(|body| body.map_err(Into::into).boxed()),
336336
Err(err) => return Ok(Err(err)),
@@ -351,10 +351,10 @@ where
351351
let request = http::Request::from_parts(request, body);
352352
match client.send_request(request, options).await? {
353353
Ok((response, io)) => {
354-
store.spawn(AccessorTaskFn(|_: &Accessor<U, Self>| async {
354+
store.spawn_fn(|_| async {
355355
_ = io.await;
356356
Ok(())
357-
}));
357+
});
358358
match response.await {
359359
Ok(response) => response.map(|body| body.map_err(Into::into).boxed()),
360360
Err(err) => return Ok(Err(err)),
@@ -371,10 +371,10 @@ where
371371
let request = http::Request::from_parts(request, body);
372372
match client.send_request(request, options).await? {
373373
Ok((response, io)) => {
374-
store.spawn(AccessorTaskFn(|_: &Accessor<U, Self>| async {
374+
store.spawn_fn(|_| async {
375375
_ = io.await;
376376
Ok(())
377-
}));
377+
});
378378
match response.await {
379379
Ok(response) => response.map(|body| body.map_err(Into::into).boxed()),
380380
Err(err) => return Ok(Err(err)),
@@ -393,10 +393,10 @@ where
393393
let request = http::Request::from_parts(request, body);
394394
match client.send_request(request, options).await? {
395395
Ok((response, io)) => {
396-
store.spawn(AccessorTaskFn(|_: &Accessor<U, Self>| async {
396+
store.spawn_fn(|_| async {
397397
_ = io.await;
398398
Ok(())
399-
}));
399+
});
400400
match response.await {
401401
Ok(response) => response.map(|body| body.map_err(Into::into).boxed()),
402402
Err(err) => return Ok(Err(err)),

0 commit comments

Comments
 (0)