Skip to content

Commit

Permalink
fix: add Send bound to Streaming wrapper (#63)
Browse files Browse the repository at this point in the history
useful for moving ownership to the spawn closure,

```
let mut response_stream = client.append_session(request).await?;

    let response_consumer = tokio::spawn(async move {
        while let Some(n) = response_stream.next().await {
            if let Err(e) = n {
                error!(?e, "receiver error")
            }
        }
    });
```
  • Loading branch information
infiniteregrets authored Nov 18, 2024
1 parent a42132d commit c36fb38
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,12 @@ impl<S: StreamingResponse> futures::Stream for ServiceStreamingResponse<S> {
}
}

/// Wrapper around `ServiceStreamingResponse` to expose publically.
pub struct Streaming<R>(Box<dyn Unpin + futures::Stream<Item = Result<R, ClientError>>>);
pub struct Streaming<R>(Box<dyn Unpin + Send + futures::Stream<Item = Result<R, ClientError>>>);

impl<R> Streaming<R> {
pub(crate) fn new<S>(s: ServiceStreamingResponse<S>) -> Self
where
S: StreamingResponse<ResponseItem = R> + 'static,
S: StreamingResponse<ResponseItem = R> + Send + 'static,
{
Self(Box::new(s))
}
Expand Down

0 comments on commit c36fb38

Please sign in to comment.