MCPcopy Index your code
hub / github.com/cryptomator/cryptomator / TaskImpl

Class TaskImpl

src/main/java/org/cryptomator/ui/common/Tasks.java:124–166  ·  view source on GitHub ↗

Adapter between java.util.function. and javafx.concurrent.

Source from the content-addressed store, hash-verified

122 * Adapter between java.util.function.* and javafx.concurrent.*
123 */
124 private static class TaskImpl<T> extends Task<T> {
125
126 private final Callable<T> callable;
127 private final Consumer<T> successHandler;
128 private List<ErrorHandler<?>> errorHandlers;
129 private final Runnable finallyHandler;
130
131 TaskImpl(Callable<T> callable, Consumer<T> successHandler, List<ErrorHandler<?>> errorHandlers, Runnable finallyHandler) {
132 this.callable = callable;
133 this.successHandler = successHandler;
134 this.errorHandlers = errorHandlers;
135 this.finallyHandler = finallyHandler;
136 }
137
138 @Override
139 protected T call() throws Exception {
140 return callable.call();
141 }
142
143 @Override
144 protected void succeeded() {
145 try {
146 successHandler.accept(getValue());
147 } finally {
148 finallyHandler.run();
149 }
150 }
151
152 @Override
153 protected void failed() {
154 try {
155 Throwable exception = getException();
156 errorHandlers.stream().filter(handler -> handler.handles(exception)).findFirst().ifPresentOrElse(exceptionHandler -> {
157 exceptionHandler.handle(exception);
158 }, () -> {
159 LOG.error("Unhandled exception", exception);
160 });
161 } finally {
162 finallyHandler.run();
163 }
164 }
165
166 }
167
168 /**
169 * A service that keeps executing the next task long as tasks are succeeding.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected