Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Promises for Java
Java
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src/com/dystudios/promise4j
.gitignore
README.md

README.md

What?

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

It is inspired by jQuery Deferreds.

Why?

Promises make asynchronous programming beautiful. And I love generics.

How?

  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!

FAQ

Something went wrong with that request. Please try again.