Class CompletionStageWrapper<T>

  • All Implemented Interfaces:
    CompletionStage<T>

    public final class CompletionStageWrapper<T>
    extends Object
    implements CompletionStage<T>
    CompletionStage wrapper which hides the implementation (e.g. such as, typically, a CompletableFuture) to prevent consumers from casting (or using CompletionStage.toCompletableFuture()) and accessing methods for "forcibly completing normally or exceptionally, probing completion status or results, or awaiting completion of a stage" (which e.g. CompletableFuture offers, but CompletionStage intentionally does not).

    This is mainly intended to let methods return CompletionStages which internally were CompletableFutures, yet prevent developers from abusing such async APIs by using them synchronously and just doing completionStage.toCompletableFuture().get() (or ((CompletableFuture)completionStage).get()).

    Author:
    Michael Vorburger.ch