File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ layout : pattern
3+ title : Promise
4+ folder : promise
5+ permalink : /patterns/promise/
6+ categories : Structural
7+ tags :
8+ - Java
9+ - Concurrency
10+ - Difficulty-Intermediate
11+ ---
12+
13+ ## Also known as
14+ CompletableFuture
15+
16+ ## Intent
17+ A Promise represents a proxy for a value not necessarily known when the promise is created. It
18+ allows you to associate dependent promises to an asynchronous action's eventual success value or
19+ failure reason. Promises are a way to write async code that still appears as though it is executing
20+ in a synchronous way.
21+
22+ ![ alt text] ( ./etc/promise.png " Promise ")
23+
24+ ## Applicability
25+ Promise pattern is applicable in concurrent programming when some work needs to be done asynchronously
26+ and:
27+
28+ * code maintainablity and readability suffers due to callback hell.
29+ * you need to compose promises and need better error handling for asynchronous tasks.
30+ * you want to use functional style of programming.
31+
32+
33+ ## Real world examples
34+
35+ * [ java.util.concurrent.CompletableFuture] ( https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html )
36+ * [ Guava ListenableFuture] ( https://github.com/google/guava/wiki/ListenableFutureExplained )
37+
38+ ## Related Patterns
39+ * Async Method Invocation
40+ * Callback
41+
42+ ## Credits
43+
44+ * [ You are missing the point to Promises] ( https://gist.github.com/domenic/3889970 )
45+ * [ Functional style callbacks using CompleteableFuture] ( https://www.infoq.com/articles/Functional-Style-Callbacks-Using-CompletableFuture )
You can’t perform that action at this time.
0 commit comments