O'Reilly logo

Clojure for Java Developers by Eduardo Díaz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required