Promises for Java
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This is a completely type-safe implementation of Promises for Java.

It is inspired by jQuery Deferreds.


Promises make asynchronous programming beautiful. And I love generics.


  1. Grab the code (I might provide a .jar soon)

  2. Create a Deferred, and return a Promise:

    protected Promise<MyResult, MyError, MyNotification> doStuff() {
        final Deferred<MyResult, MyError, MyNotification> d = new Deferred<MyResult, MyError, MyNotification>();
        // do stuff
        return d;
  3. Resolve the deferred, handle the result:

    doStuff().then(new Promise.Handler<MyResult>() {
        public void call(MyResult value) {
            // we have a result!
    // Meanwhile, in doStuff...
    d.resolve(new MyResult());
  4. Make a pipeline:

    doStuff().pipe(new Promise.PipedHandler<MyResult, MyNewResult>() {
        public MyNewResult call(MyResult value) {
            return new MyNewResult();
    }).then(new Promise.Handler<MyNewResult>() {
        public void call(MyNewResult value) {
            // we have a new result!
  5. Also chain promises, pass errors and notifications!