I\'m trying to write a construct which allows me to run computations in a given time window. Something like:
def expensiveComputation(): Double = //... some
If you are ok for the code of expensiveComputation
to check Thread.interrupted()
frequently, pretty easy. But I suppose you are not.
I don't think there is any solution that will work for arbitrary expensiveComputation
code.
The question is what are you prepared to have as constraint on expensiveComputation.
You have the deprecated and quite unsafe Thead.stop(Throwable)
too. If your code does not modify any object but those it created by itself, it might work.