Skip to content

Commit

Permalink
#6 - Enhancement of Async Error Handling in Runnable Tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
pveeckhout committed Nov 28, 2023
1 parent 3606656 commit 884da7a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/io/edpn/backend/util/ConcurrencyUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.edpn.backend.util;

import java.util.Objects;
import java.util.function.Consumer;

public class ConcurrencyUtil {

public static Runnable errorHandlingWrapper(Runnable action, Consumer<Throwable> errorHandler) {
return () -> {
try {
action.run();
} catch (Throwable e) {
if (Objects.nonNull(errorHandler)) {
errorHandler.accept(e);
} else {
e.printStackTrace();
}
}
};
}
}

0 comments on commit 884da7a

Please sign in to comment.