About the AvailableLater library

AvailableLater simplifies writing asynchronous calls by decoupling the result and hiding Thread creation.

In a normal blocking call, you can either

  1. wait for the result or
  2. spawn a thread, do the call, and get notified when the thread finishes.

AvailableLater turns this around by making (b) the default. The result of a call is a AvailableLater object, which you can listen to (get notified) for a result. Its result is not available immediately (but later)

This simplifies writing threaded applications, such as GUIs.

Example

See the source code of AvailableLaterObjectExample, in src/test/java/com/jakeapp/availablelater/AvailableLaterObjectExample.java.

You can also browse the API or look at the source directly.

Discussion

If you want to have the blocking behaviour, you simply create an AvailableLaterWaiter, which blocks until the result of the operation is available.

Contrary to Futures, AvailableLater leaves it to the callee to spawn and run the thread, or to decide if a result is instantaneously available (no thread spawn necessary, AvailableNowObject).

Finally, AvailableLaterObjects also allow the task to provides simple notifications on its progress.