Esempio n. 1
0
 /**
  * Create a Promise that is redeemed after a timeout.
  *
  * @param message The message to use to redeem the Promise.
  * @param delay The delay (expressed with the corresponding unit).
  * @param unit The Unit.
  */
 public static <A> Promise<A> timeout(A message, long delay, TimeUnit unit) {
   return FPromiseHelper.timeout(message, delay, unit);
 }
Esempio n. 2
0
 /**
  * Perform the given <code>action</code> callback when the Promise is redeemed.
  *
  * <p>The callback will be run in the default execution context.
  *
  * @param action The action to perform.
  */
 public void onRedeem(final Callback<A> action) {
   FPromiseHelper.onRedeem(this, action, HttpExecution.defaultContext());
 }
Esempio n. 3
0
 /** Creates a new Promise with no value */
 public static <A> RedeemablePromise<A> empty() {
   scala.concurrent.Promise<A> p = FPromiseHelper.empty();
   return new RedeemablePromise(p);
 }
Esempio n. 4
0
 /**
  * Completes this promise with the specified Promise, once that Promise is completed.
  *
  * @param other The value to complete with
  * @param ec An execution context
  * @return A promise giving the result of attempting to complete this promise with the other
  *     promise. If the completion was successful then the result will be true, if the completion
  *     couldn't occur then the result will be false.
  */
 public Promise<Boolean> tryCompleteWith(Promise other, ExecutionContext ec) {
   Promise<Boolean> r =
       Promise.wrap(FPromiseHelper.tryCompleteWith(this.promise, other.future, ec));
   return r;
 }
Esempio n. 5
0
 /**
  * Perform the given <code>action</code> callback if the promise encounters an exception.
  *
  * @param action The action to perform.
  * @param ec The ExecutionContext to execute the callback in.
  */
 public void onFailure(final Callback<Throwable> action, ExecutionContext ec) {
   FPromiseHelper.onFailure(this, action, ec);
 }
Esempio n. 6
0
 /**
  * Maps the result of this promise to a promise for a result of type <code>B</code>, and
  * flattens that to be a single promise for <code>B</code>.
  *
  * @param function The function to map <code>A</code> to a promise for <code>B</code>.
  * @param ec The ExecutionContext to execute the function in.
  * @return A wrapped promise for a result of type <code>B</code>
  */
 public <B> Promise<B> flatMap(
     final Function<? super A, Promise<B>> function, ExecutionContext ec) {
   return FPromiseHelper.flatMap(this, function, ec);
 }
Esempio n. 7
0
 /**
  * Create a Promise which will be redeemed with the result of a given function.
  *
  * <p>The Function0 will be run in the default ExecutionContext.
  *
  * @param function Used to fulfill the Promise.
  */
 public static <A> Promise<A> promise(Function0<A> function) {
   return FPromiseHelper.promise(function, HttpExecution.defaultContext());
 }
Esempio n. 8
0
 /**
  * Wraps this promise in a promise that will handle exceptions thrown by this Promise.
  *
  * @param function The function to handle the exception. This may, for example, convert the
  *     exception into something of type <code>T</code>, or it may throw another exception, or it
  *     may do some other handling.
  * @param ec The ExecutionContext to execute the function in.
  * @return A wrapped promise that will only throw an exception if the supplied <code>function
  *     </code> throws an exception.
  */
 public Promise<A> recover(final Function<Throwable, A> function, ExecutionContext ec) {
   return FPromiseHelper.recover(this, function, ec);
 }
Esempio n. 9
0
 /**
  * Create a new pure promise, that is, a promise with a constant value from the start.
  *
  * @param a the value for the promise
  */
 public static <A> Promise<A> pure(final A a) {
   return FPromiseHelper.pure(a);
 }
Esempio n. 10
0
 /**
  * Create a new promise throwing an exception.
  *
  * @param throwable Value to throw
  */
 public static <A> Promise<A> throwing(Throwable throwable) {
   return FPromiseHelper.throwing(throwable);
 }
Esempio n. 11
0
 /**
  * Combine the given promises into a single promise for the list of results.
  *
  * @param promises The promises to combine
  * @param ec Used to execute the sequencing operations.
  * @return A single promise whose methods act on the list of redeemed promises
  */
 public static <A> Promise<List<A>> sequence(
     Iterable<Promise<? extends A>> promises, ExecutionContext ec) {
   return FPromiseHelper.<A>sequence(promises, ec);
 }
Esempio n. 12
0
 /**
  * Combine the given promises into a single promise for the list of results.
  *
  * <p>The sequencing operations are performed in the default ExecutionContext.
  *
  * @param promises The promises to combine
  * @return A single promise whose methods act on the list of redeemed promises
  */
 public static <A> Promise<List<A>> sequence(Iterable<Promise<? extends A>> promises) {
   return FPromiseHelper.<A>sequence(promises, HttpExecution.defaultContext());
 }
Esempio n. 13
0
 /**
  * Create a Promise timer that throws a TimeoutException after a given timeout.
  *
  * <p>The returned Promise is usually combined with other Promises.
  *
  * @param delay The delay (expressed with the corresponding unit).
  * @param unit The Unit.
  * @return a promise without a real value
  */
 public static <A> Promise<scala.Unit> timeout(long delay, TimeUnit unit) {
   return FPromiseHelper.timeout(delay, unit);
 }
Esempio n. 14
0
 /**
  * Perform the given <code>action</code> callback when the Promise is redeemed.
  *
  * @param action The action to perform.
  * @param ec The ExecutionContext to execute the action in.
  */
 public void onRedeem(final Callback<A> action, ExecutionContext ec) {
   FPromiseHelper.onRedeem(this, action, ec);
 }
Esempio n. 15
0
 /**
  * Create a Promise which will be redeemed with the result of a given Function0.
  *
  * @param function Used to fulfill the Promise.
  * @param ec The ExecutionContext to run the function in.
  */
 public static <A> Promise<A> promise(Function0<A> function, ExecutionContext ec) {
   return FPromiseHelper.promise(function, ec);
 }
Esempio n. 16
0
 /**
  * Wraps this promise in a promise that will handle exceptions thrown by this Promise.
  *
  * <p>The function will be run in the default execution context.
  *
  * @param function The function to handle the exception. This may, for example, convert the
  *     exception into something of type <code>T</code>, or it may throw another exception, or it
  *     may do some other handling.
  * @return A wrapped promise that will only throw an exception if the supplied <code>function
  *     </code> throws an exception.
  */
 public Promise<A> recover(final Function<Throwable, A> function) {
   return FPromiseHelper.recover(this, function, HttpExecution.defaultContext());
 }
Esempio n. 17
0
 /**
  * Create a Promise which, after a delay, will be redeemed with the result of a given function.
  * The function will be called after the delay.
  *
  * <p>The function will be run in the default ExecutionContext.
  *
  * @param function The function to call to fulfill the Promise.
  * @param delay The time to wait.
  * @param unit The units to use for the delay.
  */
 public static <A> Promise<A> delayed(Function0<A> function, long delay, TimeUnit unit) {
   return FPromiseHelper.delayed(function, delay, unit, HttpExecution.defaultContext());
 }
Esempio n. 18
0
 /**
  * Perform the given <code>action</code> callback if the promise encounters an exception.
  *
  * <p>This action will be run in the default exceution context.
  *
  * @param action The action to perform.
  */
 public void onFailure(final Callback<Throwable> action) {
   FPromiseHelper.onFailure(this, action, HttpExecution.defaultContext());
 }
Esempio n. 19
0
 /**
  * Create a Promise which, after a delay, will be redeemed with the result of a given function.
  * The function will be called after the delay.
  *
  * @param function The function to call to fulfill the Promise.
  * @param delay The time to wait.
  * @param unit The units to use for the delay.
  * @param ec The ExecutionContext to run the Function0 in.
  */
 public static <A> Promise<A> delayed(
     Function0<A> function, long delay, TimeUnit unit, ExecutionContext ec) {
   return FPromiseHelper.delayed(function, delay, unit, ec);
 }
Esempio n. 20
0
 /**
  * Maps the result of this promise to a promise for a result of type <code>B</code>, and
  * flattens that to be a single promise for <code>B</code>.
  *
  * <p>The function will be run in the default execution context.
  *
  * @param function The function to map <code>A</code> to a promise for <code>B</code>.
  * @return A wrapped promise for a result of type <code>B</code>
  */
 public <B> Promise<B> flatMap(final Function<? super A, Promise<B>> function) {
   return FPromiseHelper.flatMap(this, function, HttpExecution.defaultContext());
 }
Esempio n. 21
0
 /**
  * Awaits for the promise to get the result.<br>
  * Throws a Throwable if the calculation providing the promise threw an exception
  *
  * @param timeout A user defined timeout
  * @param unit timeout for timeout
  * @return The promised result
  */
 public A get(long timeout, TimeUnit unit) {
   return FPromiseHelper.get(this, timeout, unit);
 }
Esempio n. 22
0
    private RedeemablePromise(scala.concurrent.Promise<A> promise) {
      super(FPromiseHelper.getFuture(promise));

      this.promise = promise;
    }
Esempio n. 23
0
 /**
  * Awaits for the promise to get the result.<br>
  * Throws a Throwable if the calculation providing the promise threw an exception
  *
  * @param timeout A user defined timeout in milliseconds
  * @return The promised result
  */
 public A get(long timeout) {
   return FPromiseHelper.get(this, timeout, TimeUnit.MILLISECONDS);
 }
Esempio n. 24
0
 /**
  * Completes this promise with the specified Promise, once that Promise is completed.
  *
  * @param other The value to complete with
  * @param ec An execution context
  * @return A promise giving the result of attempting to complete this promise with the other
  *     promise. If the completion was successful then the result will be a null value, if the
  *     completion failed then the result will be an IllegalStateException.
  */
 public Promise<Void> completeWith(Promise other, ExecutionContext ec) {
   Promise<Void> r = Promise.wrap(FPromiseHelper.completeWith(this.promise, other.future, ec));
   return r;
 }
Esempio n. 25
0
 /**
  * combines the current promise with <code>another</code> promise using `or`
  *
  * @param another
  */
 public <B> Promise<Either<A, B>> or(Promise<B> another) {
   return FPromiseHelper.or(this, another);
 }
Esempio n. 26
0
 /**
  * Combine the given promises into a single promise for the list of results.
  *
  * <p>The sequencing operations are performed in the default ExecutionContext.
  *
  * @param promises The promises to combine
  * @return A single promise whose methods act on the list of redeemed promises
  */
 public static <A> Promise<List<A>> sequence(Promise<? extends A>... promises) {
   return FPromiseHelper.<A>sequence(
       java.util.Arrays.asList(promises), HttpExecution.defaultContext());
 }
Esempio n. 27
0
 /**
  * Combine the given promises into a single promise for the list of results.
  *
  * @param ec Used to execute the sequencing operations.
  * @param promises The promises to combine
  * @return A single promise whose methods act on the list of redeemed promises
  */
 public static <A> Promise<List<A>> sequence(
     ExecutionContext ec, Promise<? extends A>... promises) {
   return FPromiseHelper.<A>sequence(java.util.Arrays.asList(promises), ec);
 }