Lift Web Framework

This example demonstrates how to use the container's Asynchronous (continuation) response capabilities such that no I/O threads are consumed during the calculation of the REST response value. Click to see the response after a 2 second delay.
/**
 * An example of Lift's RestHelper and RestContinuation
 */
object AsyncRest extends RestHelper {

  // serve the URL /async/:id
  serve {
    case "async" :: id :: _ Get _ => 

      // move the calculation to another thread
      RestContinuation.async(
        reply => {
          Thread.sleep(2000) // sleep for 2 seconds
          val name1 = Thread.currentThread.getName
          val outerSesStr = S.session.toString // this should be Empty
          
          // the code block for reply will be executed in the
          // scope of the original request and that may mean
          // that JDBC connections are consumed, etc.
          reply{
            val name2 = Thread.currentThread.getName
            val innerSesStr = S.session.toString // this should be Full()
            <i id={id}>name1: {name1} outer: {outerSesStr} name2: {name2}
            inner: {innerSesStr}</i>
          }
        })
  }
}

Lift is Copyright 2007-2010 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.
Lift version 2.3 built on Tue Apr 05 13:24:00 PDT 2011.
Stats: Total Memory: 532,938,752 Free Memory: 492,873,224 Open Sessions: 95
Updated At: Wed May 16 20:22:15 PDT 2012 Started At: Mon Mar 26 20:25:42 PDT 2012