Skip to content

Commit

Permalink
Add response channel doc
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Jul 30, 2024
1 parent 9f47eeb commit bb56f70
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/core/src/http/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,21 @@ impl Response {
{
self.body = ResBody::stream(stream);
}
/// Set response's body to channel.

/// Create a `Body` stream with an associated sender half.
///
/// Useful when wanting to stream chunks from another thread.
///
/// # Example
/// use salvo_core::prelude::*;
/// #[handler]
/// async fn hello(res: &mut Response) {
/// res.add_header("content-type", "text/plain", true).unwrap();
/// let mut tx = res.channel();
/// tokio::spawn(async move {
/// tx.send_data("Hello world").await.unwrap();
/// });
/// }
#[inline]
pub fn channel(&mut self) -> BodySender {
let (sender, body) = ResBody::channel();
Expand Down

0 comments on commit bb56f70

Please sign in to comment.