Comments (3)
Split the sample apps into Java and Scala versions to work around this.
from ping-play.
I'm following your changes and learning a lot. Fantastic work, the code is soo clean.
I might have an idea regarding error handling and the problem that headers are already sent. The header (and footer) itself could also be a Pagelet. If one important service call fails, another responce can be given (404, 301/302). This requires a little bit more waiting time and a combination of "important" Pagelets with fromSequentialPagelets and JavaScript driven fromInterleavedPagelets. This adds waiting time to the first byte, of course.
from ping-play.
@mantsak: Thanks!
I think if there is data that is absolutely critical and you want to wait for it before sending back headers, you would structure the controller code like this:
def index = Action.async {
val dataFuture1 = makeServiceCall()
val dataFuture2 = makeServiceCall()
val criticalDataFuture = makeServiceCall()
val pagelet1 = Pagelet.fromHtmlFuture(dataFuture1)
val pagelet2 = Pagelet.fromHtmlFuture(dataFuture2)
val body = HtmlStream.fromInterleavedPagelets(pagelet1, pagelet2)
for {
criticalData <- criticalDataFuture
} yield {
Ok.chunked(views.stream.myTemplate(criticalData, body))
}
}
In other words, data that you must wait for you treat as a normal Future
and only send back a response after it has redeemed. The rest of the data, you shove into an HtmlStream
(i.e. an Enumerator
) and allow it stream down whenever the data comes back, or even if there is an error. In fact, I added an example of how to handle errors while streaming in the sample apps. Check out controllers.MoreBigPipeExamples#errorHandling
.
from ping-play.
Related Issues (20)
- Invalid chunked response (play 2.3) HOT 3
- Update to Play 2.4.x with InjectedRoutesGenerator HOT 1
- Docker image fails to build HOT 1
- Extension with HTMLCompressorFilter and GzipFilter HOT 3
- Killing open, not yet retuned Promises at the end of Controller. HOT 2
- Publish artifacts automatically as part of the build instead of manually
- Finish the "Composable Pagelets" implementation and documentation HOT 5
- Add support for pagelet priorities
- Add support for only rendering content that is visible
- Add support for specifying pagelet dependencies
- Add monitoring hooks
- Turn the sample apps into Typesafe Activator templates HOT 2
- Escaping not working HOT 9
- Use html tag / content in a stream template HOT 9
- install ping-play HOT 5
- get /sample-app-common/src/main/scala/data in Java ? HOT 18
- upgrade to play 2.5 HOT 4
- Library is not compatible with Play 2.3-RC1 HOT 1
- Throwing runtime exceptions in case of chunked mode doesn't work HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ping-play.