docs: update promise

This commit is contained in:
Ilkka Seppälä
2024-05-17 17:33:56 +03:00
parent 279d227fd4
commit 6e22be370f
5 changed files with 94 additions and 243 deletions
@@ -78,7 +78,6 @@ public class App {
*
* @param args arguments
* @throws InterruptedException if main thread is interrupted.
* @throws ExecutionException if an execution error occurs.
*/
public static void main(String[] args) throws InterruptedException {
var app = new App();
@@ -123,7 +122,7 @@ public class App {
/*
* Calculate the character frequency of a file and when that promise is fulfilled,
* then promise to apply function to calculate lowest character frequency.
* then promise to apply function to calculate the lowest character frequency.
*/
private Promise<Character> lowestFrequencyChar() {
return characterFrequency().thenApply(Utility::lowestFrequencyChar);
@@ -155,7 +154,7 @@ public class App {
() -> Utility.downloadFile(urlString), executor)
.onError(
throwable -> {
throwable.printStackTrace();
LOGGER.error("An error occurred: ", throwable);
taskCompleted();
}
);
@@ -45,7 +45,7 @@ public class Promise<T> extends PromiseSupport<T> {
private Consumer<? super Throwable> exceptionHandler;
/**
* Creates a promise that will be fulfilled in future.
* Creates a promise that will be fulfilled in the future.
*/
public Promise() {
// Empty constructor
@@ -58,7 +58,7 @@ public class Utility {
.mapToObj(x -> (char) x)
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
} catch (IOException ex) {
ex.printStackTrace();
LOGGER.error("An error occurred: ", ex);
}
return Collections.emptyMap();
}
@@ -86,7 +86,7 @@ public class Utility {
try (var bufferedReader = new BufferedReader(new FileReader(fileLocation))) {
return (int) bufferedReader.lines().count();
} catch (IOException ex) {
ex.printStackTrace();
LOGGER.error("An error occurred: ", ex);
}
return 0;
}
@@ -24,11 +24,10 @@
*/
package com.iluwatar.promise;
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import org.junit.jupiter.api.Test;
/**
* Application test.
*/