Class SolvablePromise<T>

java.lang.Object
org.smallibs.concurrent.promise.impl.SolvablePromise<T>
All Implemented Interfaces:
Promise<T>, Filter<Promise,T,Promise<T>>, HK<Promise,T,Promise<T>>
Direct Known Subclasses:
PromisesSet, RunnablePromise, SolvedPromise

public class SolvablePromise<T> extends Object
  • Constructor Details

    • SolvablePromise

      public SolvablePromise()
  • Method Details

    • getFuture

      public Future<T> getFuture()
      Description copied from interface: Promise
      Provides the underlying future able to capture and returns the result or the error for a given execution
      Returns:
      a future
    • await

      public T await() throws Exception
      Description copied from interface: Promise
      This method waits for the result. This method uses a sleep/interrupt technic.
      Throws:
      Exception
    • await

      public T await(java.time.Duration duration) throws Exception
      Description copied from interface: Promise
      This method waits for the result for a maximum duration. This method uses a sleep/interrupt technic.
      Throws:
      Exception
    • onSuccess

      public Promise<T> onSuccess(java.util.function.Consumer<T> consumer)
      Description copied from interface: Promise
      Method called when the computation succeeds
      Parameters:
      consumer - The callback to be activated on success
      Returns:
      the current promise
    • onFailure

      public Promise<T> onFailure(java.util.function.Consumer<Throwable> consumer)
      Description copied from interface: Promise
      Method called when the computation fails
      Parameters:
      consumer - The callback to be activated on error
      Returns:
      the current promise
    • onComplete

      public Promise<T> onComplete(java.util.function.Consumer<Try<T>> consumer)
      Description copied from interface: Promise
      Callback called when the computation terminates
      Parameters:
      consumer - The callback to be activated on completion
      Returns:
      the current promise
    • solve

      public boolean solve(Try<T> response)
    • createFuture

      protected SolvableFuture<T> createFuture(java.util.function.Consumer<Try<T>> callbackOnComplete)
    • map

      public final <R> Promise<R> map(FunctionWithError<? super T,? extends R> function)
      Description copied from interface: Promise
      Method used to map a function. This mapping is done when the operation is a success. The result of this mapping is a new promise component.
      Specified by:
      map in interface Promise<T>
      Type Parameters:
      R - the promised value type
      Parameters:
      function - The function to applied on success which can raise an error
      Returns:
      a new promise
    • biMap

      public final <R> Promise<R> biMap(FunctionWithError<? super T,? extends R> onSuccess, FunctionWithError<? super Throwable,? extends R> onError)
      Description copied from interface: Promise
      Method used to map a function on success and another one on error. The result of this mapping is a new promise component.
      Specified by:
      biMap in interface Promise<T>
      Type Parameters:
      R - the promised value type
      Parameters:
      onSuccess - The function to applied on success which can raise an error
      onError - The function to applied on error which can also raise an error
      Returns:
      a new promise
    • flatmap

      public final <R> Promise<R> flatmap(java.util.function.Function<? super T,Promise<R>> function)
      Description copied from interface: Promise
      Method used to flatmap a function. This mapping is done when the operation is a success. The result of this mapping is a new promise component.
      Specified by:
      flatmap in interface Promise<T>
      Type Parameters:
      R - the promised value type
      Parameters:
      function - The function to applied on success
      Returns:
      a new promise
    • filter

      public final Promise<T> filter(java.util.function.Predicate<? super T> predicate)
      Description copied from interface: Filter
      Method called when the current data must be filtered using a given predicate.
      Specified by:
      filter in interface Filter<Promise,T,Promise<T>>
      Parameters:
      predicate - The filter
      Returns:
      a filtered data
    • self

      public final Promise<T> self()
      Specified by:
      self in interface HK<Promise,T,Promise<T>>