Created
June 30, 2017 14:55
-
-
Save ricsirigu/21e8f46d2c13cb1e3b9a860aa3b4b257 to your computer and use it in GitHub Desktop.
Asynchronous Rest with Scala and Lift Framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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