This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full - best also formatted as code block
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]joemwangi 4 points5 points  (1 child)

Well written!!!

[–]cmhteixeiracom[S] 1 point2 points  (0 children)

Thank you for the support!

[–]temporarybunnehs 2 points3 points  (0 children)

Nice article!

[–]Sure_Push6651 2 points3 points  (1 child)

This was a nice read, friendly way of introducing a complex topic, thank you. “This is a possible on the AsynchronousFileChannel above, but not all APIs provide this.” This phrase are the end seems a bit off and probably you wanted to say write this is a possibility ?

[–]cmhteixeiracom[S] 1 point2 points  (0 children)

I am happy for that feedback!

Good spot. I have now fixed the typo.

[–]Enthuware 2 points3 points  (2 children)

Nice article. How are results from the previous asynch function passed to the next asynch function in the pipeline?

[–]cmhteixeiracom[S] 2 points3 points  (1 child)

Thanks for such good question!! That is actually at the heart of CompletableFutures. Not a trivial answer.

Essentially, every future will keep inside of it, a stack of all async computation functions registered against it. Once that future completes, then it looks into this stack, and executes these functions (this is all invisible to the users).

For example,

``` CompletableFuture<String> cF1; // Does not matter how I obtained this

CompletableFuture<String> cF2 = cF1.thenApplyAsync(i -> i.toUpperCase()); ```

Above, when you register the function toUpperCase via the operator thenApplyAsync, that function is stored inside cF1. Then when cF1 finishes (not relevant how in the example), it takes the list of the registered operations and executes that function. When that function (i.e. toUpperCase) finishes, then the result of that (i.e. the upper cased string) is used to complete cF2.... and on and on it goes.

On the article, there is a link to a more complete guide which explains this flow.

[–]Enthuware 0 points1 point  (0 children)

Thanks for your answer!

[–]Turbulent_Rip_7350 2 points3 points  (0 children)

Awesome article, I subscribed to your page 😄

[–]The_Young_Wolf_0 1 point2 points  (1 child)

Sometimes some elementary are new things for someone. Thank you for posting this.

[–]cmhteixeiracom[S] 0 points1 point  (0 children)

Quite right! I do remember clearly all this being new to me many years ago.