MCPcopy Create free account
hub / github.com/emilk/ehttp / fetch_streaming

Function fetch_streaming

ehttp/src/streaming/web.rs:49–78  ·  view source on GitHub ↗
(
    request: Request,
    on_data: Box<dyn Fn(crate::Result<Part>) -> ControlFlow<()> + Send>,
)

Source from the content-addressed store, hash-verified

47}
48
49pub(crate) fn fetch_streaming(
50 request: Request,
51 on_data: Box<dyn Fn(crate::Result<Part>) -> ControlFlow<()> + Send>,
52) {
53 spawn_future(async move {
54 let mut stream = match fetch_jsvalue_stream(&request).await {
55 Ok(stream) => stream,
56 Err(e) => {
57 let _ = on_data(Err(string_from_fetch_error(e)));
58 return;
59 }
60 };
61
62 while let Some(chunk) = stream.next().await {
63 match chunk {
64 Ok(chunk) => {
65 if on_data(Ok(chunk)).is_break() {
66 return;
67 }
68 }
69 Err(e) => {
70 let _ = on_data(Err(string_from_fetch_error(e)));
71 return;
72 }
73 }
74 }
75
76 let _ = on_data(Ok(Part::Chunk(vec![])));
77 })
78}

Callers 1

fetchFunction · 0.70

Calls 3

spawn_futureFunction · 0.85
fetch_jsvalue_streamFunction · 0.85
string_from_fetch_errorFunction · 0.85

Tested by

no test coverage detected