Skip to content

Instantly share code, notes, and snippets.

@vincentchu
Created November 24, 2015 18:47
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 vincentchu/785b635c17e858a643b4 to your computer and use it in GitHub Desktop.
Save vincentchu/785b635c17e858a643b4 to your computer and use it in GitHub Desktop.
def someFuture(input: String): Future[String] = {
val promise = new Promise[String]
val javaFuture = someJavaFutureMethod(input)
// Use Timer to periodically check for return value of
timer.schedule(10.millis) {
if (javaFuture.isDone()) {
// Probably glossing over some edge cases around setting interrupts, timeouts, etc.. but you get the gist
begin {
promise.setValue(javaFuture.get())
} rescue {
case ex => promise.setException(ex)
}
}
}
promise
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment