This is about Task.
What's the difference between
You can think of a Continuation as something that converts some input type to some output type. If you define a
Continuation<IN, OUT>, where
IN is the input type passed to its
then method via a
OUT is the type that method returns.
continueWith, you pass a
Continuation<IN, OUT>, and the
then method is expected to compute and return the
OUT value given a
Task<IN> value as input. You might choose to do this if you don't have any blocking work to do for the conversion, such as reducing an integer array to the sum of its elements or counting the number of words in a String.
continueWithTask, you pass a
Continuation<IN, Task<OUT>>, and the
then method is expected to return a
Task<OUT> that eventually generates the
OUT value, given the
IN value as input. You might choose this if you are able to delegate the conversion work to an existing reusable Task.
Practically speaking, you aren't required to choose one or the other to do your work. It's a matter of preferred style, or if you have a nice
Task ready to delegate your conversation rather than a
Continuation. Typically you only use a Continuations if you have a pipeline of conversions to chain together.
The javadoc links here show some examples of Continuations. Also, to learn more, you can read about them in part three of my blog series. To be fair,
continueWithTask is the only part of the Task API I don't directly discuss anywhere in that series, mostly because conceptually it doesn't differ very much from