Promises

If you are a full stack Java developer, there is a good chance that you have met promises in JavaScript.

Promises are simple abstractions that don't impose strict requirements on you; you can use them to calculate the result on some other thread, light process, or anything you like.

In Java, there are a couple of ways to achieve this; one of them is with futures (java.util.concurrentFuture) and if you want something more similar to JavaScript's promise there is a nice implementation called jdeferred (https://github.com/jdeferred/jdeferred), which you might have used before.

In essence a promise is just a promise that you can give to your caller, the caller can use it at any given time. There are two possibilities:

  • If the promise has already ...

Get Clojure: High Performance JVM Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.