Created
April 11, 2014 18:18
-
-
Save dwhitney/10489490 to your computer and use it in GitHub Desktop.
Toy Scala code from talk
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
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