Class Promise<T>

  • Type Parameters:
    T - The return class of this promise - doesn't have to be a Response...but it probably will be.

    public class Promise<T>
    extends java.lang.Object
    A Promise is, as the name implies, a rough analogue of other languages (such as JS)'s "Promise" class. Internally, relies on Java's powerful CompletableFutures, but makes things a little less confusing by hiding most of the more exotic methods.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean cancel()  
      T get​(org.python.core.PyObject[] args, java.lang.String[] keywords)  
      java.util.concurrent.CompletableFuture<T> getFuture()  
      Promise handleException​(org.python.core.PyObject callback)
      Return a new promise that will run the provided callback in the event of an exception, to attempt graceful error handling.
      boolean isDone()  
      Promise then​(org.python.core.PyObject callback)
      Return a new promise that wraps this one's return value in a Python callable.
      java.lang.String toString()  
      void whenComplete​(org.python.core.PyObject callback)
      Call callback, asynchronously, whenever this future completes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • get

        public T get​(org.python.core.PyObject[] args,
                     java.lang.String[] keywords)
              throws java.lang.InterruptedException,
                     java.util.concurrent.ExecutionException,
                     java.util.concurrent.TimeoutException
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException
      • getFuture

        public java.util.concurrent.CompletableFuture<T> getFuture()
      • then

        public Promise then​(org.python.core.PyObject callback)
        Return a new promise that wraps this one's return value in a Python callable. Callable will be called wrapped in a Promise.PyBiFunction.
      • handleException

        public Promise handleException​(org.python.core.PyObject callback)
        Return a new promise that will run the provided callback in the event of an exception, to attempt graceful error handling.
      • whenComplete

        public void whenComplete​(org.python.core.PyObject callback)
        Call callback, asynchronously, whenever this future completes.
      • cancel

        public boolean cancel()
      • isDone

        public boolean isDone()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object