MCPcopy Create free account
hub / github.com/bytecodealliance/wstd / http_wait_body

Function http_wait_body

examples/http_server.rs:50–64  ·  view source on GitHub ↗
(_request: Request<Body>)

Source from the content-addressed store, hash-verified

48}
49
50async fn http_wait_body(_request: Request<Body>) -> Result<Response<Body>> {
51 // Get the time now
52 let now = Instant::now();
53
54 let body = async move {
55 // Sleep for one second.
56 wstd::task::sleep(Duration::from_secs(1)).await;
57
58 // Compute how long we slept for.
59 let elapsed = Instant::now().duration_since(now).as_millis();
60 Ok::<_, Infallible>(Bytes::from(format!("slept for {elapsed} millis\n")))
61 };
62
63 Ok(Response::new(Body::from_try_stream(once_future(body))))
64}
65
66async fn http_stream_body(_request: Request<Body>) -> Result<Response<Body>> {
67 // Get the time now

Callers 1

mainFunction · 0.85

Calls 3

sleepFunction · 0.85
as_millisMethod · 0.80
duration_sinceMethod · 0.80

Tested by

no test coverage detected