The Last Result of Heavy Event Stream Processing

There is a stream of events handled by an expensive algorithm that runs for a very long time. The results for all events, except for the last (at every moment), are not of interest. I want to handle the event, asynchronously interrupting the processing of previous events every time a new one arrives.

Are there any good templates or methods for this?

I thought:

  • participants (without cancellation)
  • futures (no cancellation)
  • (it is not clear how to choose the last event, and they are usually difficult)
  • thread pools (requires a custom solution, not a Scala method?)

I prefer to select pools with a custom intermittent task (not yet developed). Are there any better options in Scala? If not, how do I accomplish my task?

+4
source share
1 answer

The only thing I can offer is the use of Java futures and a call cancelto the future of Java. Then you need to process InterruptedException(for blocking operations) and regularly check for Thread.isInterrupted(for intensive calculations). I think you already know about it.

0
source

All Articles