File tree Expand file tree Collapse file tree 2 files changed +14
-12
lines changed
main/java/com/iluwatar/callback
test/java/com/iluwatar/callback Expand file tree Collapse file tree 2 files changed +14
-12
lines changed Original file line number Diff line number Diff line change 2929/** Template-method class for callback hook execution. */
3030public abstract class Task {
3131
32- /** Execute the task and asynchronously call the callback method upon completion.*/
32+ /** Execute the task and asynchronously call the callback method upon completion. */
3333 final void executeWith (Callback callback ) {
34- CompletableFuture .runAsync (() -> {
35- execute ();
36- if (callback != null ) {
37- callback .call ();
38- }
39- });
34+ CompletableFuture .runAsync (
35+ () -> {
36+ execute ();
37+ if (callback != null ) {
38+ callback .call ();
39+ }
40+ });
4041 }
4142
4243 public abstract void execute ();
Original file line number Diff line number Diff line change 2626
2727import static org .junit .jupiter .api .Assertions .assertEquals ;
2828
29- import org .junit .jupiter .api .Test ;
3029import java .util .concurrent .CountDownLatch ;
3130import java .util .concurrent .TimeUnit ;
31+ import org .junit .jupiter .api .Test ;
3232
3333/**
3434 * Add a field as a counter. Every time the callback method is called increment this field. Unit
@@ -45,10 +45,11 @@ void test() throws InterruptedException {
4545 CountDownLatch latch = new CountDownLatch (1 );
4646
4747 CountDownLatch finalLatch = latch ;
48- Callback callback = () -> {
49- callingCount ++;
50- finalLatch .countDown ();
51- };
48+ Callback callback =
49+ () -> {
50+ callingCount ++;
51+ finalLatch .countDown ();
52+ };
5253
5354 var task = new SimpleTask ();
5455
You can’t perform that action at this time.
0 commit comments