3 ms·
I found the continuations, and they are actually pretty nice. https://news.ycombinator.com/item?id=6125567 https://news.ycombinator.com/item?id=6125567 http:/
by anonymoushn 13y ago
I found the continuations, and they are actually pretty nice.
https://news.ycombinator.com/item?id=6125567 https://news.ycombinator.com/item?id=6125567
http://jim-mcbeath.blogspot.com/2010/08/delimited-continuations.html http://jim-mcbeath.blogspot.com/2010/08/delimited-continuati...
https://github.com/jimmc/scoroutine https://github.com/jimmc/scoroutine - some of the examples in this are godawful, but you'll find that they still work if you rewrite them to be legible.
- happy_dino 13y ago// Some example methods which might spend waiting for other // services (calling the database, sending emails). def getEMailForUsername(username: String) = future { DB.Users.find(_.name == username).get.email } def sendPassordRecoveryMail(email: EMail, message: String) = future { SMTPService.send(email, message) } // Future/Promises API: def resetPassword(username: String) = for { email <- getEMailForUsername(username) result <- sendPassordRecoveryMail(email, "some message") } yield result // Async API: def resetPassword(username: String) = async { val email = getEMailForUsername(username) val result = sendPassordRecoveryMail(email, "some message") await(result) } @smegel: I don't see any “callback hell” or “code that does look like spaghetti” here. By the way, I'd love to see a link to “Scala's synchronous API” and that mystical “far less attractive callback based API”. Or are you making things up again?