There is a stream of events being processed by a costly algorithm which executes for a very long time. Results for all events except last (at every moment) are of no interest. I want to process an event asynchronously interrupting processing of previous events each time a new one arrives.
Are there any good patterns or techniques to do so?
I've considered:
- actors (no cancellation)
- futures (no cancellation)
- threads (not clear how should last event be selected, and they are usually heavy)
- thread pools (require custom solution, not Scala way?)
I tend to choose pools, with a custom interruptible tasklet (not yet designed). Are there better options in Scala? If not how should I implement my tasklet?