[concurrency-interest] How to subclass CompletableFuture?

cowwoc cowwoc at bbs.darktech.org
Fri Oct 31 08:43:35 EDT 2014

On 30/10/2014 8:05 PM, Doug Lea [via JSR166 Concurrency] wrote:
> > Imagine we have
> > 
> MyCompletionStage.supplyAsync(...).thenApplyAsync(...).thenComplete(...);
> There is no "thenComplete", so I'm not sure what you are asking?

My mistake. The last phase was meant to be a thenApplyAsync() that 
invokes complete().

> > 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.
> In general yes. (There is a last-resort escape hatch
> obtrudeValue, with known use cases only for failure recovery.)
> >
> > Is there a way to clarify the Javadoc of CompletableFuture or
> > CompletionStage on this point (ideally by way of example code)?
> >
> Please let us know what kinds of wordings and examples would be
> helpful!

I'll give you some example paragraphs I liked and we can work together 
to come up with a specific text for CompletableFuture.

http://keyholesoftware.com/2014/07/23/javascript-promises-are-cool/ reads:

     "A rejected or resolved promise is/settled/. A promise state can 
only move from pending to settled. Thereafter its state is immutable. A 
promise can be held long after its associated action has settled. At 
leisure, we can extract the result multiple times. We carry this out by 
calling/promise.then()/. That call won’t return unless, or until, the 
associated action has been settled. We can fluidly chain promises. The 
chained “then” functions should each either return a promise, or let the 
original promise be the return value."

Further down they give a concrete example of how to flatten Promise 
chains (search for "Flattened promise chain").

I'd like the class Javadoc to make the following additional points:

  * A CompletableFuture is meant to be used by chaining together
    multiple instances together, where each stage returns a value or
    throws an exception.
  * Each stage may transform the value returned by a previous stage or
    return the original value unmodified.
  * The value returned by the initially-constructed CompletableFuture is
    equal to the value returned (or the exception thrown) by the
    last-executed stage.
  * (Provide a short example of how to flatten promise chains, inline or
    by linking to it.)

Let me know what you think.


View this message in context: http://jsr166-concurrency.10961.n7.nabble.com/How-to-subclass-CompletableFuture-tp11382p11388.html
Sent from the JSR166 Concurrency mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20141031/ceb20cd9/attachment.html>

More information about the Concurrency-interest mailing list