(_request: Request<Body>)
| 64 | } |
| 65 | |
| 66 | async fn http_stream_body(_request: Request<Body>) -> Result<Response<Body>> { |
| 67 | // Get the time now |
| 68 | let start = Instant::now(); |
| 69 | |
| 70 | let body = move |iters: usize| async move { |
| 71 | if iters == 0 { |
| 72 | return None; |
| 73 | } |
| 74 | // Sleep for 0.1 second. |
| 75 | wstd::task::sleep(Duration::from_millis(100)).await; |
| 76 | |
| 77 | // Compute how long we slept for. |
| 78 | let elapsed = Instant::now().duration_since(start).as_millis(); |
| 79 | Some(( |
| 80 | Ok::<_, Infallible>(Bytes::from(format!( |
| 81 | "stream started {elapsed} millis ago\n" |
| 82 | ))), |
| 83 | iters - 1, |
| 84 | )) |
| 85 | }; |
| 86 | |
| 87 | Ok(Response::new(Body::from_try_stream(unfold(5, body)))) |
| 88 | } |
| 89 | |
| 90 | async fn http_echo(request: Request<Body>) -> Result<Response<Body>> { |
| 91 | let (_parts, body) = request.into_parts(); |
no test coverage detected