Skip to content

Instantly share code, notes, and snippets.

@ricsirigu
Created June 30, 2017 14:55
Show Gist options
  • Save ricsirigu/21e8f46d2c13cb1e3b9a860aa3b4b257 to your computer and use it in GitHub Desktop.
Save ricsirigu/21e8f46d2c13cb1e3b9a860aa3b4b257 to your computer and use it in GitHub Desktop.
Asynchronous Rest with Scala and Lift Framework
/**
* Created by Riccardo Sirigu on 30/06/17.
*/
object AsyncRestExample extends RestHelper{
serve{
case "async" :: Nil JsonGet _ =>
val mainThreadName = Thread.currentThread.getName
RestContinuation.async{ reply =>
val backgroundThreadName = Thread.currentThread.getName
//Long running computation executing in another thread
Thread.sleep(4000)
reply {
("MainThread" -> mainThreadName) ~
("BackgroundThread" -> backgroundThreadName) ~
("Result" -> 42)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment