Skip to content

Instantly share code, notes, and snippets.

@bka9
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bka9/c0665947233e1f7e9951 to your computer and use it in GitHub Desktop.
Save bka9/c0665947233e1f7e9951 to your computer and use it in GitHub Desktop.
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