dcapwell commented on code in PR #17:
URL: https://github.com/apache/cassandra-accord/pull/17#discussion_r1110251559
##########
accord-core/src/main/java/accord/utils/async/AsyncCallbacks.java:
##########
@@ -0,0 +1,45 @@
+package accord.utils.async;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.Executor;
+import java.util.function.BiConsumer;
+
+public class AsyncCallbacks
+{
+ private static final Logger logger =
LoggerFactory.getLogger(AsyncCallbacks.class);
+
+ private static final BiConsumer<Object, Throwable> NOOP = (unused,
failure) -> {
+ if (failure != null)
+ logger.error("Exception received by noop callback", failure);
+ };
+
+ public static <T> BiConsumer<? super T, Throwable> noop()
+ {
+ return NOOP;
+ }
+
+ public static <T> BiConsumer<? super T, Throwable> inExecutor(BiConsumer<?
super T, Throwable> callback, Executor executor)
+ {
+ return (result, throwable) -> {
+ try
+ {
+ executor.execute(() -> callback.accept(result, throwable));
+ }
+ catch (Throwable t)
+ {
+ callback.accept(null, t);
+ }
+ };
+ }
+
+
+ public static <T> BiConsumer<? super T, Throwable> inExecutor(Runnable
runnable, Executor executor)
+ {
+ return (result, throwable) -> {
+ if (throwable == null) executor.execute(runnable);
+ else throw new RuntimeException(throwable);
+ };
+ }
+}
Review Comment:
copy/pasted these tests and ran them again, still seeing this behavior;
`begin` is throwing rather than giving the exception to the callback
The only tests that do not fail are
```
AsyncChains.<Integer>ofCallable(fn -> fn.run(), () -> {
throw new RuntimeException("Unchecked");
}).map(i -> i + 1).map(i -> i + 1)
.begin((success, failure) -> {
if (failure == null)
throw new IllegalStateException("Should see
failure");
});
AsyncChains.ofCallable(fn -> fn.run(), () -> 42
).map(i -> i + 1)
.map(ignore -> {
throw new RuntimeException("Unchecked");
})
.begin((success, failure) -> {
if (failure == null)
throw new IllegalStateException("Should see
failure");
});
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]