CompletableFuture dependent ordering

Benjamin Manes via Concurrency-interest <[email protected]> Mon, 4 Jan 2021 14:28:44 -0800
Newsgroups gmane.comp.java.jsr.166-concurrency
Message-ID <CAGu0=MO9wXvr6BxXnvw7c30doB-pNnGqgZhhSLADgJKH-RgP8w@mail.gmail.com>
Hi everyone,

CompletableFuture maintains a Treiber stack for processing dependents, such
as "thenAccept" and "whenComplete" actions. I couldn't find a previous
discussion on this design decision. Can you please educate me on why a LIFO
stack was preferred over a FIFO queue?

The current behavior seems less intuitive and a lack of awareness can cause
subtle surprises. While chaining against the dependent can resolve these
gotchas most of the time, there are scenarios where it is more correct to
work with the original future instance and to chain dependents on the side.
This has come up a few times regarding an asynchronous cache and while I
have educated users on this behavior, a workaround within the cache would
merely shift the pain by no longer returning the user's supplied future
instance. While I can understand the stack might have been preferred as a
more elegant implementation, I do not yet see why it would be better by its
external behavior.

Thanks and happy new year.

_______________________________________________
Concurrency-interest mailing list
[email protected]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest