Skip to content

Instantly share code, notes, and snippets.

@dwhitney
Created April 11, 2014 18:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwhitney/10489490 to your computer and use it in GitHub Desktop.
Save dwhitney/10489490 to your computer and use it in GitHub Desktop.
Toy Scala code from talk
package controllers
import play.api._
import play.api.mvc._
import scala.concurrent._
import scala.concurrent.Future._
//import play.api.libs.concurrent.Execution.Implicits._
import scala.concurrent.ExecutionContext
import java.util.concurrent.Executors
import java.util.Random
import scala.concurrent.stm._
object Application extends Controller {
val executor = Executors.newFixedThreadPool(1)
implicit val context = ExecutionContext.fromExecutorService(executor)
def randomWalk(i: Int): Future[Int] = Future {
val random = new Random
var total = 0
for(_ <- 0 to i){
if(random.nextBoolean) total = total + 1
else total = total - 1
}
total
}
def index = Action.async {
val future1 = randomWalk(1000000000)
val future2 = randomWalk(1000000000)
for(i in myarra)
val future3 = for{
x <- future1
y <- future2
} yield x + y
future3.map( i => Ok(i.toString))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment