[concurrency-interest] How to subclass CompletableFuture?
cowwoc at bbs.darktech.org
Thu Oct 30 17:46:58 EDT 2014
On 30/10/2014 5:00 PM, Doug Lea [via JSR166 Concurrency] wrote:
> On 10/26/2014 10:21 PM, cowwoc wrote:
> > Hi,
> > I believe that CompletableFuture was designed to allow for
> subclassing but I
> > can't seem to figure out how to implement such a subclass:
> > http://stackoverflow.com/q/26579139/14731
> I was about to answer this, but I see that Holger already posted
> one good approach on stackoverflow. Thanks Holger!
> One further note though: One reason interface CompletionStage exists
> is so that you don't have to subclass CompletableFuture, or
> use it in any way at all for alternative implementations. However,
> the handy static methods to get chains started aren't available,
> so you'd need to provide alternatives.
Holger pretty much nailed the answer, but I did have a related question:
is complete() equivalent to internalComplete()? Meaning, can one
implement supplyAsync() as follows?
CompletionStage<T> supplyAsync(Supplier<T> s, Executor e)
CompletionStage<T> result = new MyCompletionStage(...);
Imagine we have
The Javadoc for complete() sound as if we're locking the future's value
such that subsequent operations (i.e. thenApplyAsync()) cannot invoke
complete() with a different value. Does complete() work this way or do
you mean that the proceeding code consists of 3 stages and each stage
may only invoke complete() once?
Is there a way to clarify the Javadoc of CompletableFuture or
CompletionStage on this point (ideally by way of example code)?
View this message in context: http://jsr166-concurrency.10961.n7.nabble.com/How-to-subclass-CompletableFuture-tp11382p11386.html
Sent from the JSR166 Concurrency mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest