Class LazyPromise<T>

java.lang.Object
io.deephaven.web.client.fu.LazyPromise<T>

public class LazyPromise<T> extends Object
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!
  • Field Details

  • Constructor Details

    • LazyPromise

      public LazyPromise()
  • Method Details

    • ofObject

      public static Throwable ofObject(Object obj)
    • toJsError

      public static Object toJsError(Throwable throwable)
      The JS error behind throwable, which ofObject(Object) maps back to it: what JS sees when Java throws.
    • 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, the same one on every call. 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)
    • onFailure

      public void onFailure(JsConsumer<Object> failure)
    • 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()