Class DefaultFutures

java.lang.Object
play.libs.concurrent.DefaultFutures
All Implemented Interfaces:
Futures

public class DefaultFutures extends Object implements Futures
The default implementation of the Futures trait. This provides an implementation that uses the scheduler of the application's ActorSystem.
  • Constructor Details

    • DefaultFutures

      @Inject public DefaultFutures(play.api.libs.concurrent.Futures delegate)
  • Method Details

    • timeout

      public <A> CompletionStage<A> timeout(CompletionStage<A> stage, long amount, TimeUnit unit)
      Creates a CompletionStage that returns either the input stage, or a futures.

      Note that timeout is not the same as cancellation. Even in case of futures, the given completion stage will still complete, even though that completed value is not returned.

      Specified by:
      timeout in interface Futures
      Type Parameters:
      A - the completion's result type.
      Parameters:
      stage - the input completion stage that may time out.
      amount - The amount (expressed with the corresponding unit).
      unit - The time Unit.
      Returns:
      either the completed future, or a completion stage that failed with futures.
    • timeout

      public <A> CompletionStage<A> timeout(CompletionStage<A> stage, Duration duration)
      An alias for futures(stage, delay, unit) that uses a java.time.Duration.
      Specified by:
      timeout in interface Futures
      Type Parameters:
      A - the completion stage that should be wrapped with a future.
      Parameters:
      stage - the input completion stage that may time out.
      duration - The duration after which there is a timeout.
      Returns:
      the completion stage, or a completion stage that failed with futures.
    • delayed

      public <A> CompletionStage<A> delayed(Callable<CompletionStage<A>> callable, long amount, TimeUnit unit)
      Create a CompletionStage which, after a delay, will be redeemed with the result of a given supplier. The supplier will be called after the delay.
      Specified by:
      delayed in interface Futures
      Type Parameters:
      A - the type of the completion's result.
      Parameters:
      callable - the input completion stage that is delayed.
      amount - The time to wait.
      unit - The units to use for the amount.
      Returns:
      the delayed CompletionStage wrapping supplier.
    • delay

      public CompletionStage<Done> delay(Duration duration)
      Description copied from interface: Futures
      Creates a completion stage which is only completed after the delay.
      
       Duration expected = Duration.ofSeconds(2);
       long start = System.currentTimeMillis();
       CompletionStage<Long> stage = futures.delay(expected).thenApply((v) -> {
           long end = System.currentTimeMillis();
           return (end - start);
       });
       
      Specified by:
      delay in interface Futures
      Parameters:
      duration - the duration after which the completion stage is run.
      Returns:
      the completion stage.
    • delay

      public CompletionStage<Done> delay(long amount, TimeUnit unit)
      Description copied from interface: Futures
      Creates a completion stage which is only completed after the delay.
      Specified by:
      delay in interface Futures
      Parameters:
      amount - The time to wait.
      unit - The units to use for the amount.
      Returns:
      the delayed CompletionStage.
    • delayed

      public <A> CompletionStage<A> delayed(Callable<CompletionStage<A>> callable, Duration duration)
      Create a CompletionStage which, after a delay, will be redeemed with the result of a given supplier. The supplier will be called after the delay.
      Specified by:
      delayed in interface Futures
      Type Parameters:
      A - the type of the completion's result.
      Parameters:
      callable - the input completion stage that is delayed.
      duration - to wait.
      Returns:
      the delayed CompletionStage wrapping supplier.