Skip to main content

stream

Function stream 

Source
pub fn stream<T: Into<Bytes>>() -> (Sender<T>, impl Body<Data = Bytes, Error = Error>)
Available on crate feature http only.
Expand description

Create a streaming body, with a Sender for writing to the body. This supports strings, Bytes, Vec<u8>, and any IntoIterator<Item = u8>. For types which are not Into<Bytes>, use stream_any.

ยงExamples

use futures::SinkExt;

let (mut tx, body) = stream::<String>();

spin_sdk::wasip3::spawn(async move {
    for i in 0..10000 {
        if tx.send(format!("{i}\n")).await.is_err() {
            break;
        }
    }
});

let response = Response::new(body);