简体   繁体   中英

What is the equivalent of C++'s Futures in Java

I was looking for an asynchronous way of setting a variable and notify the possible listeners that the variable is now available.

C++ has a great API for this use case called std::future ( wait and set_value ). But the Future's of Java are completely different...

Is there an alternative API in Java that accomplished the same behavior like in C++?

Credit goes to @JornVernee for providing an answer in the comments

You are looking for CompletableFuture :

A Future that may be explicitly completed (setting its value and status), and may be used as a CompletionStage, supporting dependent functions and actions that trigger upon its completion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM