Advertisement
Carcigenicate

Future Test

Jan 27th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.59 KB | None | 0 0
  1. package futures
  2.  
  3. import scala.concurrent._
  4. import duration._
  5. import ExecutionContext.Implicits.global
  6. import scala.language.postfixOps
  7.  
  8. object FutureTestMain {
  9.    
  10.     def wasteTime(n: Int): Int =
  11.         (1 to n).foldLeft(1) { (x,y) =>
  12.         x + y + Math.sqrt(x * y).toInt
  13.     }
  14.    
  15.     def main(args: Array[String]) = {
  16.        
  17.         val n = 10000000
  18.        
  19.         println("Starting")
  20.    
  21.         val fut: Future[Int] = Future {
  22.             wasteTime(n)
  23.         }
  24.        
  25.         val x = wasteTime(n * 2)
  26.        
  27.         println("Inter Result: " + x)
  28.    
  29.         val result = Await.result(fut, 10 seconds)
  30.        
  31.         println("Future Result: " + result)
  32.        
  33.     }
  34.    
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement