I have to run complex, async computations and be able to abort them at any time (from outside the computation).
The current implementation uses scala.concurrent.Future to run the computations. However, there doesn't seem to be an obvious way to cancel a scala Future during execution.
I've found and tried a number of recommended solutions to this issue, such as using a Promise to implement a cancellable Future or using java.util.concurrent.Future which has a cancel() method.
All of them have the same problem: the execution only aborts when it reaches a Thread.sleep() call.
This is a problem for two reasons:
- The computations should finish as quickly as possible. Adding even very short sleep periods is counterproductive.
- I'm not the main developer of these computations and I want to avoid having to impose arbitrary constraints on the implementation of the computations.