Giter VIP home page Giter VIP logo

Comments (3)

brikis98 avatar brikis98 commented on June 5, 2024

Split the sample apps into Java and Scala versions to work around this.

from ping-play.

mantsak avatar mantsak commented on June 5, 2024

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.

brikis98 avatar brikis98 commented on June 5, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.