类 AbstractPromise<D>

java.lang.Object
cn.dinodev.spring.commons.promise.AbstractPromise<D>
所有已实现的接口:
Promise<D>, Supplier<D>
直接已知子类:
DeferredObject

public abstract class AbstractPromise<D> extends Object implements Promise<D>
作者:
Cody Lu
  • 字段详细资料

  • 构造器详细资料

    • AbstractPromise

      public AbstractPromise()
  • 方法详细资料

    • state

      public Promise.State state()
      从接口复制的说明: Promise
      状态
      指定者:
      state 在接口中 Promise<D>
      返回:
      the state of this promise.
    • done

      public Promise<D> done(Consumer<? super D> callback)
      从接口复制的说明: Promise
      This method will register DoneCallback so that when a Deferred object is resolved (Deferred.resolve(Object)), DoneCallback will be triggered. If the Deferred object is already resolved then the DoneCallback is triggered immediately. You can register multiple DoneCallback by calling the method multiple times. The order of callback trigger is based on the order they have been registered.
       
       promise.progress(new DoneCallback(){
         public void onDone(Object done) {
           ...
         }
       });
       
       
      指定者:
      done 在接口中 Promise<D>
      参数:
      callback - the callback to be triggered
      返回:
      this for chaining more calls
      另请参阅:
    • fail

      public Promise<D> fail(Consumer<Throwable> callback)
      从接口复制的说明: Promise
      This method will register FailCallback so that when a Deferred object is rejected (Deferred#reject(Object)), FailCallback will be triggered. If the Deferred object is already rejected then the FailCallback is triggered immediately. You can register multiple FailCallback by calling the method multiple times. The order of callback trigger is based on the order they have been registered.
       
       promise.fail(new FailCallback(){
         public void onFail(Object rejection) {
           ...
         }
       });
       
       
      指定者:
      fail 在接口中 Promise<D>
      参数:
      callback - the callback to be triggered
      返回:
      this for chaining more calls
      另请参阅:
      • Deferred#reject(Object)
    • always

      public Promise<D> always(AlwaysCallback<? super D> callback)
      从接口复制的说明: Promise
      This method will register AlwaysCallback so that when a Deferred object is either resolved (Deferred.resolve(Object)) or rejected (Deferred#reject(Object)), AlwaysCallback will be triggered. If the Deferred object is already resolved or rejected then the AlwaysCallback is triggered immediately. You can register multiple AlwaysCallback by calling the method multiple times. The order of callback trigger is based on the order they have been registered. AlwaysCallbacks are triggered after any DoneCallback or FailCallback respectively.
       
       promise.always(new AlwaysCallback(){
         public void onAlways(State state, Object result, Object rejection) {
           if (state == State.RESOLVED) {
             // do something with result
           } else {
             // do something with rejection
           }
         }
       });
       
       
      指定者:
      always 在接口中 Promise<D>
      参数:
      callback - the callback to be triggered
      返回:
      this for chaining more calls
      另请参阅:
    • triggerDone

      protected void triggerDone(D resolved)
    • triggerDone

      protected void triggerDone(Consumer<? super D> callback, D resolved)
    • triggerFail

      protected void triggerFail(Throwable rejected)
    • triggerFail

      protected void triggerFail(Consumer<Throwable> callback, Throwable rejected)
    • triggerAlways

      protected void triggerAlways(Promise.State state, D resolve, Throwable reject)
    • triggerAlways

      protected void triggerAlways(AlwaysCallback<? super D> callback, Promise.State state, D resolve, Throwable reject)
    • then

      public Promise<D> then(Consumer<? super D> callback)
      从接口复制的说明: Promise
      指定者:
      then 在接口中 Promise<D>
      参数:
      callback - see Promise.done(DoneCallback)
      返回:
      this for chaining more calls
    • then

      public Promise<D> then(Consumer<? super D> doneCallback, Consumer<Throwable> failCallback)
      从接口复制的说明: Promise
      指定者:
      then 在接口中 Promise<D>
      参数:
      doneCallback - see Promise.done(DoneCallback)
      failCallback - see Promise.fail(FailCallback)
      返回:
      this for chaining more calls
    • isPending

      public boolean isPending()
      从接口复制的说明: Promise
      Queries the state of this promise, returning true iff it is State.PENDING.
      指定者:
      isPending 在接口中 Promise<D>
      返回:
      true if the current state of this promise is State.PENDING, false otherwise.
      另请参阅:
    • isResolved

      public boolean isResolved()
      从接口复制的说明: Promise
      Queries the state of this promise, returning true iff it is State.RESOLVED.
      指定者:
      isResolved 在接口中 Promise<D>
      返回:
      true if the current state of this promise is State.RESOLVED, false otherwise.
      另请参阅:
    • isRejected

      public boolean isRejected()
      从接口复制的说明: Promise
      Queries the state of this promise, returning true iff it is State.REJECTED.
      指定者:
      isRejected 在接口中 Promise<D>
      返回:
      true if the current state of this promise is State.REJECTED, false otherwise.
      另请参阅:
    • waitSafely

      public void waitSafely() throws InterruptedException
      从接口复制的说明: Promise
      This method will wait as long as the State is Pending. This method will return fast when State is not Pending.
      指定者:
      waitSafely 在接口中 Promise<D>
      抛出:
      InterruptedException - if thread is interrupted while waiting
    • waitSafely

      public void waitSafely(long timeout) throws InterruptedException
      从接口复制的说明: Promise
      This method will wait when the State is Pending, and return when timeout has reached. This method will return fast when State is not Pending.
      指定者:
      waitSafely 在接口中 Promise<D>
      参数:
      timeout - the maximum time to wait in milliseconds
      抛出:
      InterruptedException - if thread is interrupted while waiting
    • get

      public D get()
      指定者:
      get 在接口中 Supplier<D>
    • getOrElse

      public D getOrElse(D defaultValue)
      从接口复制的说明: Promise
      get the resolved value, return defaultValue for rejected
      指定者:
      getOrElse 在接口中 Promise<D>
      返回:
    • getOrElse

      public D getOrElse(Supplier<D> valueSupplier)
      从接口复制的说明: Promise
      get the resolved value, return defaultSupplier‘s result for rejected
      指定者:
      getOrElse 在接口中 Promise<D>
      返回:
    • handleException

      protected void handleException(AbstractPromise.CallbackType callbackType, Exception e)