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

Function fetch_jsvalue_stream

ehttp/src/streaming/web.rs:27–47  ·  view source on GitHub ↗
(
    request: &Request,
)

Source from the content-addressed store, hash-verified

25
26#[cfg(feature = "streaming")]
27async fn fetch_jsvalue_stream(
28 request: &Request,
29) -> Result<impl Stream<Item = Result<Part, JsValue>>, JsValue> {
30 use js_sys::Uint8Array;
31
32 let response = fetch_base(request).await?;
33 let body = wasm_streams::ReadableStream::from_raw(
34 response.body().ok_or("response has no body")?.dyn_into()?,
35 );
36
37 // returns a `Part::Response` followed by all the chunks in `body` as `Part::Chunk`
38 Ok(
39 futures_util::stream::once(futures_util::future::ready(Ok(Part::Response(
40 get_response_base(&response)?,
41 ))))
42 .chain(
43 body.into_stream()
44 .map(|value| value.map(|value| Part::Chunk(Uint8Array::new(&value).to_vec()))),
45 ),
46 )
47}
48
49pub(crate) fn fetch_streaming(
50 request: Request,

Callers 2

fetch_async_streamingFunction · 0.85
fetch_streamingFunction · 0.85

Calls 3

fetch_baseFunction · 0.85
ResponseClass · 0.85
get_response_baseFunction · 0.85

Tested by

no test coverage detected