Class LazyPromise<T>

java.lang.Object
io.deephaven.web.client.fu.LazyPromise<T>
All Implemented Interfaces:
PromiseLike<T>

public class LazyPromise<T> extends Object implements PromiseLike<T>
Tired of needing to create annoying promise lambdas? If you want to create a promise early in a method's scope, and then configure it's handling of resolve/reject callbacks later, or in a conditional nature, than LazyPromise is for you!
  • Constructor Details

    • LazyPromise

      public LazyPromise()
  • Method Details

    • ofObject

      public static Throwable ofObject(Object obj)
    • runLater

      @JsIgnore public static void runLater(JsRunnable task)
    • asPromise

      public final elemental2.promise.Promise<T> asPromise(int timeout)
      Parameters:
      timeout - How many millis to wait until failing the promise with a timeout.
      Returns:
      a real promise that we will resolve when we are resolved. This method overload is not strictly necessary to call when explicitly wiring up failure handling for this LazyPromise which you can guarantee will be eventually called. To create a promise without a timeout, see asPromise().
    • asPromise

      public final elemental2.promise.Promise<T> asPromise()
      Returns:
      a real promise that we will resolve when we are resolved. Use this method if you are safely wiring up failure handling for this LazyPromise. If you aren't explicitly wiring up calls to fail(Object) this LazyPromise, then you should setup a timeout (see asPromise(int) and timeout(int)
    • asPromise

      public final CancellablePromise<T> asPromise(JsRunnable cancel)
    • asPromise

      public final <V> CancellablePromise<V> asPromise(JsFunction<T,V> mapper, JsRunnable cancel)
    • isUnresolved

      public boolean isUnresolved()
    • isResolved

      public boolean isResolved()
    • isFailure

      public boolean isFailure()
    • isSuccess

      public boolean isSuccess()
    • isFulfilled

      public boolean isFulfilled()
    • fail

      public void fail(Object reason)
    • succeed

      public void succeed(T value)
    • onSuccess

      public void onSuccess(JsConsumer<T> success)
      Specified by:
      onSuccess in interface PromiseLike<T>
    • onFailure

      public void onFailure(JsConsumer<Object> failure)
      Specified by:
      onFailure in interface PromiseLike<T>
    • promiseLater

      public static <T> elemental2.promise.Promise<T> promiseLater(T table)
      Create a deferred promise from a known value. Rather than resolve immediately, this forces asynchronicity, to give the calling code time to unwind its stack before running.
    • reject

      public static <V> elemental2.promise.IThenable<V> reject(Object failure)
    • timeout

      public LazyPromise<T> timeout(int wait)
    • logError

      public static <T> elemental2.promise.Promise.CatchOnRejectedCallbackFn<T> logError(JsProvider<String> msg)
      Eats exceptions in exchange for messages logged to the console. Only use this when it is preferable to print a nice error message instead of leaving uncaught promises to bubble (confusing) stack traces into console, especially if it is reasonable for a given promise to fail. This prevents "uncaught exceptions" when we have tests that expect failure.
    • asCallback

      public Callback<T,String> asCallback()