ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jdk8/java/util/concurrent/CompletionStage.java
(Generate patch)

Comparing jsr166/src/jdk8/java/util/concurrent/CompletionStage.java (file contents):
Revision 1.1 by jsr166, Sat Mar 26 06:22:49 2016 UTC vs.
Revision 1.2 by jsr166, Mon Oct 1 03:58:19 2018 UTC

# Line 822 | Line 822 | public interface CompletionStage<T> {
822          (Function<Throwable, ? extends T> fn);
823  
824      /**
825 +     * Returns a new CompletionStage that, when this stage completes
826 +     * exceptionally, is executed with this stage's exception as the
827 +     * argument to the supplied function, using this stage's default
828 +     * asynchronous execution facility.  Otherwise, if this stage
829 +     * completes normally, then the returned stage also completes
830 +     * normally with the same value.
831 +     *
832 +     * @implSpec The default implementation invokes {@link #handle},
833 +     * relaying to {@link #handleAsync} on exception, then {@link
834 +     * #thenCompose} for result.
835 +     *
836 +     * @param fn the function to use to compute the value of the
837 +     * returned CompletionStage if this CompletionStage completed
838 +     * exceptionally
839 +     * @return the new CompletionStage
840 +     * @since 12
841 +     */
842 +    public default CompletionStage<T> exceptionallyAsync
843 +        (Function<Throwable, ? extends T> fn) {
844 +        return handle((r, ex) -> (ex == null)
845 +                      ? this
846 +                      : this.<T>handleAsync((r1, ex1) -> fn.apply(ex1)))
847 +            .thenCompose(Function.identity());
848 +    }
849 +
850 +    /**
851 +     * Returns a new CompletionStage that, when this stage completes
852 +     * exceptionally, is executed with this stage's exception as the
853 +     * argument to the supplied function, using the supplied Executor.
854 +     * Otherwise, if this stage completes normally, then the returned
855 +     * stage also completes normally with the same value.
856 +     *
857 +     * @implSpec The default implementation invokes {@link #handle},
858 +     * relaying to {@link #handleAsync} on exception, then {@link
859 +     * #thenCompose} for result.
860 +     *
861 +     * @param fn the function to use to compute the value of the
862 +     * returned CompletionStage if this CompletionStage completed
863 +     * exceptionally
864 +     * @param executor the executor to use for asynchronous execution
865 +     * @return the new CompletionStage
866 +     * @since 12
867 +     */
868 +    public default CompletionStage<T> exceptionallyAsync
869 +        (Function<Throwable, ? extends T> fn, Executor executor) {
870 +        return handle((r, ex) -> (ex == null)
871 +                      ? this
872 +                      : this.<T>handleAsync((r1, ex1) -> fn.apply(ex1), executor))
873 +            .thenCompose(Function.identity());
874 +    }
875 +
876 +    /**
877 +     * Returns a new CompletionStage that, when this stage completes
878 +     * exceptionally, is composed using the results of the supplied
879 +     * function applied to this stage's exception.
880 +     *
881 +     * @implSpec The default implementation invokes {@link #handle},
882 +     * invoking the given function on exception, then {@link
883 +     * #thenCompose} for result.
884 +     *
885 +     * @param fn the function to use to compute the returned
886 +     * CompletionStage if this CompletionStage completed exceptionally
887 +     * @return the new CompletionStage
888 +     * @since 12
889 +     */
890 +    public default CompletionStage<T> exceptionallyCompose
891 +        (Function<Throwable, ? extends CompletionStage<T>> fn) {
892 +        return handle((r, ex) -> (ex == null)
893 +                      ? this
894 +                      : fn.apply(ex))
895 +            .thenCompose(Function.identity());
896 +    }
897 +
898 +    /**
899 +     * Returns a new CompletionStage that, when this stage completes
900 +     * exceptionally, is composed using the results of the supplied
901 +     * function applied to this stage's exception, using this stage's
902 +     * default asynchronous execution facility.
903 +     *
904 +     * @implSpec The default implementation invokes {@link #handle},
905 +     * relaying to {@link #handleAsync} on exception, then {@link
906 +     * #thenCompose} for result.
907 +     *
908 +     * @param fn the function to use to compute the returned
909 +     * CompletionStage if this CompletionStage completed exceptionally
910 +     * @return the new CompletionStage
911 +     * @since 12
912 +     */
913 +    public default CompletionStage<T> exceptionallyComposeAsync
914 +        (Function<Throwable, ? extends CompletionStage<T>> fn) {
915 +        return handle((r, ex) -> (ex == null)
916 +                      ? this
917 +                      : this.handleAsync((r1, ex1) -> fn.apply(ex1))
918 +                        .thenCompose(Function.identity()))
919 +            .thenCompose(Function.identity());
920 +    }
921 +
922 +    /**
923 +     * Returns a new CompletionStage that, when this stage completes
924 +     * exceptionally, is composed using the results of the supplied
925 +     * function applied to this stage's exception, using the
926 +     * supplied Executor.
927 +     *
928 +     * @implSpec The default implementation invokes {@link #handle},
929 +     * relaying to {@link #handleAsync} on exception, then {@link
930 +     * #thenCompose} for result.
931 +     *
932 +     * @param fn the function to use to compute the returned
933 +     * CompletionStage if this CompletionStage completed exceptionally
934 +     * @param executor the executor to use for asynchronous execution
935 +     * @return the new CompletionStage
936 +     * @since 12
937 +     */
938 +    public default CompletionStage<T> exceptionallyComposeAsync
939 +        (Function<Throwable, ? extends CompletionStage<T>> fn,
940 +         Executor executor) {
941 +        return handle((r, ex) -> (ex == null)
942 +                      ? this
943 +                      : this.handleAsync((r1, ex1) -> fn.apply(ex1), executor)
944 +                        .thenCompose(Function.identity()))
945 +            .thenCompose(Function.identity());
946 +    }
947 +
948 +    /**
949       * Returns a {@link CompletableFuture} maintaining the same
950       * completion properties as this stage. If this stage is already a
951       * CompletableFuture, this method may return this stage itself.
952       * Otherwise, invocation of this method may be equivalent in
953       * effect to {@code thenApply(x -> x)}, but returning an instance
954 <     * of type {@code CompletableFuture}. A CompletionStage
831 <     * implementation that does not choose to interoperate with others
832 <     * may throw {@code UnsupportedOperationException}.
954 >     * of type {@code CompletableFuture}.
955       *
956       * @return the CompletableFuture
835     * @throws UnsupportedOperationException if this implementation
836     * does not interoperate with CompletableFuture
957       */
958      public CompletableFuture<T> toCompletableFuture();
959  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines