Skip to content

Commit 8983f9c

Browse files
committed
Update README.md
1 parent 9b464e0 commit 8983f9c

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

callback/README.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,26 @@ tags:
99
---
1010

1111
## Intent
12-
Callback is a piece of executable code that is passed as an argument to other code, which is expected to call back
13-
(execute) the argument at some convenient time.
12+
13+
Callback is a piece of executable code that is passed as an argument to other code, which is
14+
expected to call back (execute) the argument at some convenient time.
1415

1516
## Explanation
1617

1718
Real world example
1819

19-
> We need to be notified after executing task has finished. We pass a callback method for the executor and wait for it to call back on us.
20+
> We need to be notified after executing task has finished. We pass a callback method for
21+
> the executor and wait for it to call back on us.
2022
2123
In plain words
2224

2325
> Callback is a method passed to the executor which will be called at defined moment.
2426
2527
Wikipedia says
2628

27-
> In computer programming, a callback, also known as a "call-after" function, is any executable code that is passed as an argument to other code; that other code is expected to call back (execute) the argument at a given time.
29+
> In computer programming, a callback, also known as a "call-after" function, is any executable
30+
> code that is passed as an argument to other code; that other code is expected to call
31+
> back (execute) the argument at a given time.
2832
2933
**Programmatic Example**
3034

@@ -61,21 +65,23 @@ public final class SimpleTask extends Task {
6165
}
6266
```
6367

64-
Finally here's how we execute a task and receive a callback when it's finished.
68+
Finally, here's how we execute a task and receive a callback when it's finished.
6569

6670
```java
6771
var task = new SimpleTask();
6872
task.executeWith(() -> LOGGER.info("I'm done now."));
6973
```
7074

7175
## Class diagram
76+
7277
![alt text](./etc/callback.png "Callback")
7378

7479
## Applicability
80+
7581
Use the Callback pattern when
7682

7783
* when some arbitrary synchronous or asynchronous action must be performed after execution of some defined activity.
7884

7985
## Real world examples
8086

81-
* [CyclicBarrier](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CyclicBarrier.html#CyclicBarrier%28int,%20java.lang.Runnable%29) constructor can accept callback that will be triggered every time when barrier is tripped.
87+
* [CyclicBarrier](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CyclicBarrier.html#CyclicBarrier%28int,%20java.lang.Runnable%29) constructor can accept a callback that will be triggered every time a barrier is tripped.

callback/etc/callback.png

9.45 KB
Loading

callback/etc/callback.urm.puml

-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ package com.iluwatar.callback {
88
interface Callback {
99
+ call() {abstract}
1010
}
11-
class LambdasApp {
12-
- LOGGER : Logger {static}
13-
- LambdasApp()
14-
+ main(args : String[]) {static}
15-
}
1611
class SimpleTask {
1712
- LOGGER : Logger {static}
1813
+ SimpleTask()

0 commit comments

Comments
 (0)