Skip to content

Instantly share code, notes, and snippets.

@brikis98
Last active December 15, 2015 09:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brikis98/5235967 to your computer and use it in GitHub Desktop.
Save brikis98/5235967 to your computer and use it in GitHub Desktop.
// A single wrapper method for all the instrumentation functions
def withInstrumentation[T](f: => Future[T], fallback: T, duration: Long = 5000): Future[T] = {
withErrorHandling(
withTimeout(withTiming(f), duration, fallback),
fallback
)
}
val myFuture = withInstrumentation(someAsyncIO(), "fallback value")
val result: Future[Result] = myFuture.map { str =>
// str either contains the result of the async I/O or
// "fallback value" if there was an error or timeout
Ok(str)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment