Last active
August 29, 2015 14:10
-
-
Save bka9/c0665947233e1f7e9951 to your computer and use it in GitHub Desktop.
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
def f() = Future{ | |
sleep(2000) | |
println "Calling future." | |
"Hello World!" | |
} | |
def time[A](title: String)(fut: => Future[A])(implicit context: ExecutionContext):Future[A] = { | |
val timer = System.currentTimeMillis() | |
fut.onComplete(_ => | |
println(s"""${title} took: ${System.currentTimeMillis-timer} ms to complete.""") | |
) | |
fut | |
} | |
val e = time("test future"){f()}.either() | |
e match { | |
case Right(s) => println(s) | |
case Left(e) => e.printStackTrace | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment