Skip to content

Instantly share code, notes, and snippets.

@dabd
Created February 1, 2016 09:29
Show Gist options
  • Save dabd/f0134aa9cf5bf94e6a25 to your computer and use it in GitHub Desktop.
Save dabd/f0134aa9cf5bf94e6a25 to your computer and use it in GitHub Desktop.
import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
def runWithTimeout[T](timeoutMs: Long)(f: => Future[T]) : T = {
Await.result(f, timeoutMs.millis)
}
runWithTimeout(50) { Future { "result" } }
runWithTimeout(50) { Future { throw new Exception("deliberate") } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment