diff --git a/src/java/com/samskivert/util/ResultHandler.java b/src/java/com/samskivert/util/ResultHandler.java index 3a855286..faaaed3f 100644 --- a/src/java/com/samskivert/util/ResultHandler.java +++ b/src/java/com/samskivert/util/ResultHandler.java @@ -18,11 +18,11 @@ public class ResultHandler */ public void getResult (ResultListener rl) { - if (_result != null) { - rl.requestCompleted(_result); - } else if (_error != null) { + if (_error != null) { rl.requestFailed(_error); - } else { // _list != null + } else if (_list == null) { // _list == null when we have a result + rl.requestCompleted(_result); + } else { _list.add(rl); } } @@ -30,23 +30,30 @@ public class ResultHandler // documentation inherited from interface ResultListener public void requestCompleted (T result) { - _list.requestCompleted(_result = result); + _result = result; + ResultListener list = _list; _list = null; + + list.requestCompleted(result); } // documentation inherited from interface ResultListener public void requestFailed (Exception cause) { - _list.requestFailed(_error = cause); + _error = cause; + ResultListener list = _list; _list = null; + + list.requestFailed(cause); } - /** When waiting for the result, the list of registered listeners. */ + /** If non-null, indicates that we're waiting for the result and holds the list of registered + * listeners. */ protected ResultListenerList _list = new ResultListenerList(); - /** The result, if it was obtained successfully. */ - protected T _result; - - /** The cause of the failure, if the result could not be obtained. */ + /** If non-null, the cause of the failure to obtain a result. */ protected Exception _error; + + /** The result. */ + protected T _result; }