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 29
29
/** Template-method class for callback hook execution. */
30
30
public abstract class Task {
31
31
32
- /** Execute the task and asynchronously call the callback method upon completion.*/
32
+ /** Execute the task and asynchronously call the callback method upon completion. */
33
33
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
+ });
40
41
}
41
42
42
43
public abstract void execute ();
Original file line number Diff line number Diff line change 26
26
27
27
import static org .junit .jupiter .api .Assertions .assertEquals ;
28
28
29
- import org .junit .jupiter .api .Test ;
30
29
import java .util .concurrent .CountDownLatch ;
31
30
import java .util .concurrent .TimeUnit ;
31
+ import org .junit .jupiter .api .Test ;
32
32
33
33
/**
34
34
* 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 {
45
45
CountDownLatch latch = new CountDownLatch (1 );
46
46
47
47
CountDownLatch finalLatch = latch ;
48
- Callback callback = () -> {
49
- callingCount ++;
50
- finalLatch .countDown ();
51
- };
48
+ Callback callback =
49
+ () -> {
50
+ callingCount ++;
51
+ finalLatch .countDown ();
52
+ };
52
53
53
54
var task = new SimpleTask ();
54
55
You can’t perform that action at this time.
0 commit comments