Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompletableFuture anyOf #371

Open
Ryanng-zr opened this issue Apr 26, 2021 · 4 comments
Open

CompletableFuture anyOf #371

Ryanng-zr opened this issue Apr 26, 2021 · 4 comments

Comments

@Ryanng-zr
Copy link

Hi guys, I am aware that anyOf returns the first value that is completed, however what if all the CompletableFutures complete at the same time? Which value will be returned in this case?

image

@kexinnnwang
Copy link

I believe anyOf would come in handy if you have method chains after it. After any of the cfs is completed, the next method can then run (which is different from allOf, which requires all to be completed). I dont think the order will be fixed because just like allOf, the order changes each time you run it

@clementyee303
Copy link

I'm guessing the choice of return would be arbitrary if both were to be completed at the exact same time, much like a comparator returning 0 for a sort - the order is chosen randomly

@Brandon-Chiu
Copy link

Hi, I think that the value which will be returned will not be fixed because the first returned value can vary.

@JWulaXia
Copy link

i think if all finishes on the same time then maybe the computer then randomly choose one to proceed to the next round. this anyof is most handy when you just need one value to proceed to the next stage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants