Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport returning a Stream #149
Comments
lfairy
added
the
enhancement
label
Aug 29, 2018
This comment has been minimized.
This comment has been minimized.
|
What's your intended use case for this feature? My first thought would be to apply pagination or use Ajax calls instead. Streaming raises some difficult design issues that I'd rather not deal with unless there's a strong need for it. In particular, if the stream raises an error in the middle of rendering a page, then a naive solution would leave the page cut off. That's not a nice user experience IMO. There are ways to handle this problem (e.g. display an error message inline), but the options at that point are more constrained than if all the data was fetched in advance. (Sorry for the lack of response. I should have asked this question before applying the label.) |
This comment has been minimized.
This comment has been minimized.
sorin-davidoi
commented
Sep 5, 2018
The main use-case is to improve performance - don't want to have a blank page for 2 seconds while the database query is running. Would also want to keep as much of the logic server-side, so no Ajax calls and maintaining state on the client. I think that if we enforce that all the futures have the type |
This comment has been minimized.
This comment has been minimized.
|
I have also encountered this use-case when using home-grown logging interfaces that render That exact use case might be kind of an anti-pattern, but I'm sympathetic to this change. Mostly because, in theory, it should be feasible to yield valid chunks of HTML tokens as a stream. The question is if it can be done in an elegant way, and if it can work nicely with various frameworks. On the framework front, async support is uneven. Rocket uses its own interface for streaming responses, for instance. Which frameworks are you targeting? |
This comment has been minimized.
This comment has been minimized.
sorin-davidoi
commented
Sep 22, 2018
|
I was looking to target #[cfg(feature = "hyper")]
mod hyper_support {
use PreEscaped;
use hyper::body::Payload;
use hyper::{Chunk, Error};
use futures::Async;
impl Payload for PreEscaped<String> {
type Data = Chunk;
type Error = Error;
fn poll_data(&mut self) -> Result<Async<Option<Self::Data>>, Self::Error> {
Ok(Async::Ready(Some(Chunk::from(self.0.clone()))))
}
}
} |
sorin-davidoi commentedAug 29, 2018
Would be an interesting direction to explore. The main use-case would be streaming HTML to the browsers without blocking on database calls.