I usually see the use of either promise and future in the start of a vert.x verticle. Is there any specific difference between both? I have read about their differences in Scala language, is it the same in case of Vert.x too? Also when should I know when to use promise or a future?
Futures and promises are pretty similar concepts, the difference is that a future is a read-only container for a result that does not yet exist, while a promise can be written (normally only once).
In Java 8, the Future<T> interface has methods to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation when it is complete. CompletableFutures can be thought of as a promise, since their value can be explicitly set.
Programming Languages of the Future Learning and using programming languages is an essential part of a software developer's job. The programming languages of the future are Go, Kotlin, Python, TypeScript, R, Scala, Swift, Rust, Ruby, and Haskell,as reported by TechRepublic.
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference. @FunctionalInterface public interface Handler<E> A generic event handler. This interface is used heavily throughout Vert. x as a handler for all types of asynchronous occurrences.
The best I've read about:
think on Promise as producer (used by producer on one side of async operation) and Future as consumer (used by consumer on the other side).
Futures vs. Promises
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With