Created
November 24, 2015 18:47
-
-
Save vincentchu/785b635c17e858a643b4 to your computer and use it in GitHub Desktop.
This file contains 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
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