In this problem I have to call a third-party Java library that expects a java.util.concurrent.Future
with a result from a Scala routine returning a scala.concurrent.Future
as for example.
def someScalaFunction(): scala.concurrent.Future[T]
def otherJavaMethod(arg: java.util.concurrent.Future[T]) = ...
I would wrap the Scala-Future into a new Java-Future, however there is no way to implement the Java-Future method def cancel(mayInterruptIfRunning: Boolean): Boolean
in a way it interrupts the wrapped Scala-Future (if otherwise please let me know).
How can I solve this problem? These are the approaches I come up with:
- write the wrapper anyway and just ignore the call on
cancel
(or throw anNotImplementedError
) - change
someScalaFunction
to maybe return a closure that will then be wrapped by the caller in a Scala or Java Future.
The problem with 1. is that some client could rely on the proper implementation of cancel
but is maybe not very critical.
2. would result in a really ugly api.