Interface Deferred<D,​F,​P>

    • Method Detail

      • resolve

        Deferred<D,​F,​P> resolve​(D resolve)
        This should be called when a task has completed successfully.

         
         Deferred deferredObject = new DeferredObject();
         Promise promise = deferredObject.promise();
         promise.done(new DoneCallback() {
           public void onDone(Object result) {
                // Done!
           }
         });
        
         // another thread using the same deferredObject
         deferredObject.resolve("OK");
        
         
         
        Parameters:
        resolve - the resolved value for this Deferred
        Returns:
        the reference to this Deferred instance.
      • reject

        Deferred<D,​F,​P> reject​(F reject)
        This should be called when a task has completed unsuccessfully, i.e., a failure may have occurred.

         
         Deferred deferredObject = new DeferredObject();
         Promise promise = deferredObject.promise();
         promise.fail(new FailCallback() {
           public void onFail(Object result) {
                // Failed :(
           }
         });
        
         // another thread using the same deferredObject
         deferredObject.reject("BAD");
        
         
         
        Parameters:
        reject - the rejected value for this Deferred
        Returns:
        the reference to this Deferred instance.
      • notify

        Deferred<D,​F,​P> notify​(P progress)
        This should be called when a task is still executing and progress had been made, E.g., during a file download, notify the download progress.

         
         Deferred deferredObject = new DeferredObject();
         Promise promise = deferredObject.promise();
         promise.progress(new ProgressCallback() {
           public void onProgress(Object progress) {
                // Failed :(
           }
         });
        
         // another thread using the same deferredObject
         deferredObject.reject("100%");
        
         
         
        Parameters:
        progress - the intermediate result for this Deferred
        Returns:
        the reference to this Deferred instance.
      • promise

        Promise<D,​F,​P> promise()
        Return an Promise instance (i.e., an observer). You can register callbacks in this observer.
        Returns:
        the reference to this Deferred instance as a Promise,