Skip to content

Instantly share code, notes, and snippets.

@debasishg
Created March 22, 2013 16:12
Show Gist options
  • Select an option

  • Save debasishg/5222566 to your computer and use it in GitHub Desktop.

Select an option

Save debasishg/5222566 to your computer and use it in GitHub Desktop.
The timeout exception is trapped by the Failure clause of Try.
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_43).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.util.Try
import scala.util.Try
scala> import scala.util.{Success, Failure}
import scala.util.{Success, Failure}
scala> import scala.concurrent._
import scala.concurrent._
scala> import scala.concurrent.duration._
import scala.concurrent.duration._
scala> import ExecutionContext.Implicits.global
import ExecutionContext.Implicits.global
scala> val f = future[Int]{ do{} while(true); 1 }
f: scala.concurrent.Future[Int] = scala.concurrent.impl.Promise$DefaultPromise@9695ed7
scala> def foo = Try { Await.result(f, 3 seconds) }
foo: scala.util.Try[Int]
scala> foo match {
| case Success(i) => println(i)
| case Failure(f) => println(f.getMessage)
| }
Futures timed out after [3 seconds]
scala>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment