Last active
December 15, 2015 09:09
-
-
Save brikis98/5235967 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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