Skip to content

Commit

Permalink
AsyncSupport.ThrowingSupplier: narrow allowed exceptions to IOException
Browse files Browse the repository at this point in the history
This class was intended to be used to wrap JSON-RPC I/O methods of JsonRpcClient
that throw IOException (and subclasses such as JsonRpcException) so this
breaking change is meant to enforce that.
  • Loading branch information
msgilligan committed Jul 25, 2023
1 parent 95e1554 commit fb9c334
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.consensusj.jsonrpc;

import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Supplier;
Expand All @@ -13,7 +14,7 @@ public interface AsyncSupport {
/**
* Supply async for a ThrowingSupplier by catching exceptions and completing exceptionally.
*
* @param throwingSupplier Supplier of T that can throw an exception
* @param throwingSupplier Supplier of T that can throw an {@code IOException}
* @param <T> return type
* @return A completable future, returning T
*/
Expand All @@ -24,7 +25,7 @@ default <T> CompletableFuture<T> supplyAsync(ThrowingSupplier<T> throwingSupplie
/**
* Supply async for a ThrowingSupplier by catching exceptions and completing exceptionally.
*
* @param throwingSupplier Supplier of T that can throw an exception
* @param throwingSupplier Supplier of T that can throw an {@code IOException}
* @param executor Executor to run the Supplier
* @param <T> return type
* @return A completable future, returning T
Expand Down Expand Up @@ -56,14 +57,17 @@ static <T> CompletableFuture<T> supplyCatchingAsync(ThrowingSupplier<T> throwing
}

/**
* Subinterface of {@link Supplier} for Lambdas which throw exceptions.
* Subinterface of {@link Supplier} for Lambdas which throw {@link IOException}.
* Can be used for two purposes:
* <ol>
* <li>To cast a lambda that throws an exception to a {@link Supplier} while
* <li>To cast a lambda that throws an {@code IOException} to a {@link Supplier} while
* automatically wrapping any exception thrown by the lambda with {@link RuntimeException}.</li>
* <li>As a {@code FunctionalInterface} where a lambda that throws exceptions is
* expected or allowed.</li>
* </ol>
* This is intended to be used to wrap JSON-RPC I/O methods of {@link JsonRpcClient} that throw {@link IOException} and
* subclasses such as {@link JsonRpcException}, so we have narrowed the allowed exceptions in {@link #getThrows()} to
* {@link IOException}.
*
* @param <T>
*/
Expand All @@ -87,8 +91,8 @@ default T get() {
* Gets a result.
*
* @return a result
* @throws Exception Any checked Exception
* @throws IOException A (checked) exception
*/
T getThrows() throws Exception;
T getThrows() throws IOException;
}
}

0 comments on commit fb9c334

Please sign in to comment.