I'm currently trying to implement some feature that implies making one request after the other, but cancelling the previous one.
When the spice manager executes a request, it is added to the requestQueue which is a shared variable used in the service that runs the logic, but it is scheduled for execution. The same happens when a cancel() message is sent (it is scheduled and executed async), but it uses an executor service. Both functions use a shared lock to handle concurrency.
The thing is that I need to send to execute a new Request after cancelling the current one (or all the existent ones), but as the cancel operation is async I've got a race condition against the execution of the last request added. Sometimes it gets cancelled too.
I've seen a private method in SpiceManager (cancelAllRequestsInternal()) that does the cancelling stuff. It is indeed the logic of the runnable that is sent to be executed in the ExecutorService. So, would it be correct to expose this method in the api? Is there any other way to cancel a/all request/s synchronously?
Matías