Clone wiki

SSPromise / Home


SSPromise is an Objective-C implementation of promises, also known as futures, delays or faults.

What are promises?

The basic idea is that instead of a callback returning data, an asynchronous operation should return a temporary value that once the operation completes resolves into the real object, transparently. More information on Wikipedia.

What's different about this implementation?

Many promises are blocking -- that is, accessing the promise will block until it has resolved. I chose to take a different path; if you try to operate on a promise before it's resolved an exception will be thrown. So make sure you check -hasResolved before trying to use a promise.

Aside from its own interface, SSPromise is fully transparent. Messages sent to it will travel through the ObjC forwarding system's fast path (-forwardingTargetForSelector:) to the resolved object. If you need/want to access that object directly use the -force method.

On Snow Leopard, SSPromise has support for block arguments for both resolving the promise and being notified about resolution events.

What's next?

There are a lot of very cool use cases for promises, especially if you subclass SSPromise to make it deal better with specific types of data (images, HTTP responses, etc).