4
4
5
5
In this session, we will explore the concepts of asynchronous and parallel programming with the ColdBox Async Manager and Java’s Completable Futures APIs. We will explore the concept of async computations, async pipelines, exception handling, scheduling and so much more. Pain 💊 medication is not included.
6
6
7
-
8
- * 🐦 ** Twitter** : [ @lmajano ] ( https://twitter.com/lmajano ) [ @bdw429s ] ( https://twitter.com/bdw429s ) [ @ortussolutions ] ( https://twitter.com/ortussolutions )
9
- * 🔗 ** Site** : https://www.ortussolutions.com
7
+
8
+ - 🐦 ** Twitter** :
9
+ - [ @lmajano ] ( https://twitter.com/lmajano )
10
+ - [ @bdw429s ] ( https://twitter.com/bdw429s )
11
+ - [ @ortussolutions ] ( https://twitter.com/ortussolutions )
12
+ - 🔗 ** Site** : https://www.ortussolutions.com
13
+ - 📖 ** Docs** : https://coldbox.ortusbooks.com/digging-deeper/promises-async-programming
10
14
11
15
12
16
## 📅 Agenda
@@ -15,177 +19,177 @@ In this session, we will explore the concepts of asynchronous and parallel progr
15
19
16
20
> Brad
17
21
18
- * Intros, Get to know you, What do you want from the workshop?
22
+ - Intros, Get to know you, What do you want from the workshop?
19
23
20
24
> Luis
21
25
22
- * [ ] The NB (non-blocking) movement
23
- * [ ] Has made NodeJS shine, but other languages support this as well.
24
- * [ ] Movement to more async/parallel computations
25
- * [ ] Overall movement to the async world
26
- * [ ] Lessons from Callbacks
27
- * [ ] Also refered to as ** Callback hell** 🔥
28
- * Example: [ Callback Hell] ( samples/00-callback-hell.md )
29
- * [ ] Can make developers cry 😢
30
- * [ ] Never ending nesting collection of closures/functions 🕷️
31
- * [ ] Callbacks could be called multiple times by the other library.
32
- * [ ] Who has been there before? Don't lie! 🤥
33
- * [ ] Movement to ** promises**
34
- * [ ] JavaScript has made this very popular
35
- * [ ] To get some sanity back into to development from call back hellfire 🔥
36
- * [ ] What is a promise?
37
- * [ ] Can have 3 different states:
38
- * ` Resolve ` : When completed
39
- * ` Reject ` : Error or something else
40
- * ` Pending ` : Not executing just yet
41
- * [ ] Cancel and Resolve them programmatically
42
- * [ ] Two channels of communication [ Promises Track] ( samples/01-promises-track.md )
43
- * ` Data `
44
- * ` Error `
45
- * [ ] What about ColdFusion?
46
- * [ ] ` cfthread ` , right?? right? right? 🤔
47
- * [ ] Great BUUUUUUT for ** very very very very** basic threading
48
- * [ ] Easy, but plagued with issues, which makes developers ** ALSO** cry :😢
49
- * [ ] No way to choose where it runs (thread pool)
50
- * [ ] No concept of returning data, it's up to you to monitor/track/report data
51
- * [ ] Hard to manage them (cancel, monitor, pause), you are on your own buddy!
52
- * [ ] No functional approaches to coding them
53
- * [ ] Managing multiple threads and joining can be cumbersome and terrifying 🧟♀️
54
- * [ ] Example: [ Interceptor State Manager - Process Async All] ( coldbox/system/web/context/InterceptorState.cfc )
55
- * [ ] ` runAsync() ` => Nothing existed until ACF2018/Lucee 5.3
56
- * [ ] A step up, but not a big step
57
- * [ ] Still Many Issues:
58
- * [ ] Backed by a custom wrapper to ` java.util.concurrent.Future `
59
- * [ ] Simplistic error handler with no way to recover or continue executing pipelines after an exception. Concept of two tracks is broken!
60
- * [ ] No way to choose or reuse the executor to run the sub-sequent ` then() ` operations. Lucee actually creates a new ` singleThreadExecutor() ` for EVERY ` then() ` operation.
61
- * [ ] No way to operate on multiple futures at once
62
- * [ runAsync() example] ( samples/02-runAsync-limitations.cfc )
63
- * [ ] No way to combine/compose futures
64
- * [ ] Only works with closures, does not work on actually calling component methods
65
- * [ ] ` xmap(), xeach() ` parallel processing
66
- * Adobe 2021+ & Lucee 5+
67
- * Limited to 50 threads in Adobe, 10 standard edition
68
- * Easy to use
69
- * Not easy to do exception handling, actually, you can't except wrap things in multiple try/catches
70
- * It does short circuit exception handling
71
- * NO Control over it
72
- * It will break out whenever an exception is detected and leave unprocessed items in a collection
73
- * No consistency
74
- * No logging
75
- * Example: [ Native Parallel Programming] ( samples/03-parallel-native.cfc )
76
- * [ ] Asynchronous Programming is NOT Easy!
77
- * [ ] Concurrency issues / Race conditions
78
- * Know the limitations on shared resources
79
- * Some data structures allow for multiple threads, some don’t, some you need to wrap to make them concurrent
80
- * ` java.util.concurrent package ` package
81
- * Read before write
82
- * Locking becomes part of your life, unfortunately
83
- * Atomic operations
84
- * Idempotent operations
85
- * Time stamps
86
- * [ ] Dealing with multiple threads
87
- * ` cfthread ` you have to be the manager
88
- * ` runAsync ` you can't be the manager
89
- * Sharing data between threads
90
- * [ ] No more ` writedump/aborts `
91
- * Logs become your best friend
92
- * ColdBox Debugger Panels: tracers and request profilers
93
- * Easy to spot an asynchronous developers...... They are in the corner, crying! 😭
94
- * [ ] 🤢 We have three approaches to threading which are extremely simplistic and not very powerful at all.
26
+ - [ ] The NB (non-blocking) movement
27
+ - [ ] Has made NodeJS shine, but other languages support this as well.
28
+ - [ ] Movement to more async/parallel computations
29
+ - [ ] Overall movement to the async world
30
+ - [ ] Lessons from Callbacks
31
+ - [ ] Also refered to as ** Callback hell** 🔥
32
+ - Example: [ Callback Hell] ( samples/00-callback-hell.md )
33
+ - [ ] Can make developers cry 😢
34
+ - [ ] Never ending nesting collection of closures/functions 🕷️
35
+ - [ ] Callbacks could be called multiple times by the other library.
36
+ - [ ] Who has been there before? Don't lie! 🤥
37
+ - [ ] Movement to ** promises**
38
+ - [ ] JavaScript has made this very popular
39
+ - [ ] To get some sanity back into to development from call back hellfire 🔥
40
+ - [ ] What is a promise?
41
+ - [ ] Can have 3 different states:
42
+ - ` Resolve ` : When completed
43
+ - ` Reject ` : Error or something else
44
+ - ` Pending ` : Not executing just yet
45
+ - [ ] Cancel and Resolve them programmatically
46
+ - [ ] Two channels of communication [ Promises Track] ( samples/01-promises-track.md )
47
+ - ` Data `
48
+ - ` Error `
49
+ - [ ] What about ColdFusion?
50
+ - [ ] ` cfthread ` , right?? right? right? 🤔
51
+ - [ ] Great BUUUUUUT for ** very very very very** basic threading
52
+ - [ ] Easy, but plagued with issues, which makes developers ** ALSO** cry :😢
53
+ - [ ] No way to choose where it runs (thread pool)
54
+ - [ ] No concept of returning data, it's up to you to monitor/track/report data
55
+ - [ ] Hard to manage them (cancel, monitor, pause), you are on your own buddy!
56
+ - [ ] No functional approaches to coding them
57
+ - [ ] Managing multiple threads and joining can be cumbersome and terrifying 🧟♀️
58
+ - [ ] Example: [ Interceptor State Manager - Process Async All] ( coldbox/system/web/context/InterceptorState.cfc )
59
+ - [ ] ` runAsync() ` => Nothing existed until ACF2018/Lucee 5.3
60
+ - [ ] A step up, but not a big step
61
+ - [ ] Still Many Issues:
62
+ - [ ] Backed by a custom wrapper to ` java.util.concurrent.Future `
63
+ - [ ] Simplistic error handler with no way to recover or continue executing pipelines after an exception. Concept of two tracks is broken!
64
+ - [ ] No way to choose or reuse the executor to run the sub-sequent ` then() ` operations. Lucee actually creates a new ` singleThreadExecutor() ` for EVERY ` then() ` operation.
65
+ - [ ] No way to operate on multiple futures at once
66
+ - [ runAsync() example] ( samples/02-runAsync-limitations.cfc )
67
+ - [ ] No way to combine/compose futures
68
+ - [ ] Only works with closures, does not work on actually calling component methods
69
+ - [ ] ` xmap(), xeach() ` parallel processing
70
+ - Adobe 2021+ & Lucee 5+
71
+ - Limited to 50 threads in Adobe, 10 standard edition
72
+ - Easy to use
73
+ - Not easy to do exception handling, actually, you can't except wrap things in multiple try/catches
74
+ - It does short circuit exception handling
75
+ - NO Control over it
76
+ - It will break out whenever an exception is detected and leave unprocessed items in a collection
77
+ - No consistency
78
+ - No logging
79
+ - Example: [ Native Parallel Programming] ( samples/03-parallel-native.cfc )
80
+ - [ ] Asynchronous Programming is NOT Easy!
81
+ - [ ] Concurrency issues / Race conditions
82
+ - Know the limitations on shared resources
83
+ - Some data structures allow for multiple threads, some don’t, some you need to wrap to make them concurrent
84
+ - ` java.util.concurrent package ` package
85
+ - Read before write
86
+ - Locking becomes part of your life, unfortunately
87
+ - Atomic operations
88
+ - Idempotent operations
89
+ - Time stamps
90
+ - [ ] Dealing with multiple threads
91
+ - ` cfthread ` you have to be the manager
92
+ - ` runAsync ` you can't be the manager
93
+ - Sharing data between threads
94
+ - [ ] No more ` writedump/aborts `
95
+ - Logs become your best friend
96
+ - ColdBox Debugger Panels: tracers and request profilers
97
+ - Easy to spot an asynchronous developers...... They are in the corner, crying! 😭
98
+ - [ ] 🤢 We have three approaches to threading which are extremely simplistic and not very powerful at all.
95
99
96
100
### Intro to ColdBox Futures
97
101
98
102
> Brad
99
103
100
- * [ ] ColdBox Futures are similar to JavaScript Promises but backed by the Java API of ` CompletableFuture `
101
- * [ ] JDK 8 Introduced ` CompletableFutures ` , ` CompletionStages ` , Executors, Lambdas and much more.
102
- * [ ] 🦄 Java ` CompletableFutures ` are like JavaScript Promises, but you know Java devs, over complicate things, even names!
103
- * [ ] We have ported the majority of this functionality to CFML: ` ColdBox Futures `
104
- * ColdBox, WireBox, CacheBox and LogBox
105
- * [ ] Adapted for our dynamic language => many enhancements
106
- * [ ] ` AsyncManager ` class in charge of all async capabilities
107
- * [ ] Standalone: create an instance as a singleton
108
- * [ ] ColdBox: ` async() ` or ` inject:AsyncManager@coldbox `
109
- * [ ] Functions:
110
- * [ ] Create Futures
111
- * [ ] Create/Manage Executors
112
- * [ ] Create/Manage Schedule Tasks
113
- * [ ] Intro to Executors
114
- * [ ] What is an executor
115
- * [ ] Default Executor is the Fork Join Pool
116
- * [ ] We can customize it and create new ones as well
117
- * [ ] Creating the Future!!
118
- * [ ] [ cbFutures Stages] ( samples/04-cbfutures-stages.md )
119
- * [ ] [ Create a future] ( samples/05-creating-future.cfc )
120
- * [ ] [ Exercise 01] ( exercises/01-intro-to-futures.cfc )
121
- * [ Solution 01] ( solutions/01-intro-to-futures.cfc )
104
+ - [ ] ColdBox Futures are similar to JavaScript Promises but backed by the Java API of ` CompletableFuture `
105
+ - [ ] JDK 8 Introduced ` CompletableFutures ` , ` CompletionStages ` , Executors, Lambdas and much more.
106
+ - [ ] 🦄 Java ` CompletableFutures ` are like JavaScript Promises, but you know Java devs, over complicate things, even names!
107
+ - [ ] We have ported the majority of this functionality to CFML: ` ColdBox Futures `
108
+ - ColdBox, WireBox, CacheBox and LogBox
109
+ - [ ] Adapted for our dynamic language => many enhancements
110
+ - [ ] ` AsyncManager ` class in charge of all async capabilities
111
+ - [ ] Standalone: create an instance as a singleton
112
+ - [ ] ColdBox: ` async() ` or ` inject:AsyncManager@coldbox `
113
+ - [ ] Functions:
114
+ - [ ] Create Futures
115
+ - [ ] Create/Manage Executors
116
+ - [ ] Create/Manage Schedule Tasks
117
+ - [ ] Intro to Executors
118
+ - [ ] What is an executor
119
+ - [ ] Default Executor is the Fork Join Pool
120
+ - [ ] We can customize it and create new ones as well
121
+ - [ ] Creating the Future!!
122
+ - [ ] [ cbFutures Stages] ( samples/04-cbfutures-stages.md )
123
+ - [ ] [ Create a future] ( samples/05-creating-future.cfc )
124
+ - [ ] [ Exercise 01] ( exercises/01-intro-to-futures.cfc )
125
+ - [ Solution 01] ( solutions/01-intro-to-futures.cfc )
122
126
123
127
### Magical Pipelines
124
128
125
129
> Luis
126
130
127
- * [ ] 🎩 [ Magical Pipelines] ( samples/06-then.cfc )
128
- * [ ] Java API: ` thenApply() ` , ` thenAccept() ` , ` thenRun() ` , why?
129
- * [ ![ Java Pipeline Methods Explained] ( samples/21-java-completable-future-methods-explained.png )] ( http://codeflex.co/java-multithreading-completablefuture-explained/ )
130
- * [ ] CF API: ` then() ` and ` thenRun() ` (Easier + Dynamic API)
131
- * [ ] Curiosity: ` CompletableFutures ` never end! This is So Ironic! Sharknado! :shark :
132
- * [ Data Transformations] ( samples/07-data-transformations.cfc )
133
- * [ Dealing with Timeouts] ( samples/08-timeouts.cfc )
134
- * Success on timeout
135
- * Exception on timeout
136
- * [ Checking status] ( samples/09-statuschecks.cfc )
137
- * Pipelines are independent of data
138
- * [ ] [ Exercise 02] ( exercises/02-pipelines-and-statuses.cfc )
139
- * [ Solution 02] ( solutions/02-pipelines-and-statuses.cfc )
131
+ - [ ] 🎩 [ Magical Pipelines] ( samples/06-then.cfc )
132
+ - [ ] Java API: ` thenApply() ` , ` thenAccept() ` , ` thenRun() ` , why?
133
+ - [ ![ Java Pipeline Methods Explained] ( samples/21-java-completable-future-methods-explained.png )] ( http://codeflex.co/java-multithreading-completablefuture-explained/ )
134
+ - [ ] CF API: ` then() ` and ` thenRun() ` (Easier + Dynamic API)
135
+ - [ ] Curiosity: ` CompletableFutures ` never end! This is So Ironic! Sharknado! :shark :
136
+ - [ Data Transformations] ( samples/07-data-transformations.cfc )
137
+ - [ Dealing with Timeouts] ( samples/08-timeouts.cfc )
138
+ - Success on timeout
139
+ - Exception on timeout
140
+ - [ Checking status] ( samples/09-statuschecks.cfc )
141
+ - Pipelines are independent of data
142
+ - [ ] [ Exercise 02] ( exercises/02-pipelines-and-statuses.cfc )
143
+ - [ Solution 02] ( solutions/02-pipelines-and-statuses.cfc )
140
144
141
145
### Dealing With Exceptions
142
146
143
147
> Brad
144
148
145
- * [ ] Everybody has problems, our code has them too, sometimes...
146
- * [ ] Let's review the promises [ data/error tracks] ( samples/04-cbfutures-stages.md )
147
- * [ ] [ Dealing with Exceptions] ( samples/10-exceptions.cfc )
148
- * [ ] Built-in logging - [ example] ( samples/10-exceptions-logging.cfc ) @Brad
149
- * [ ] ` handle ` methods - both results and exceptions - [ example] ( samples/10-exceptions-handle.cfc ) @Brad
150
- * [ ] [ Custom logging] ( samples/10-exceptions-custom-logging.cfc ) @Brad
151
- * [ ] Recovering with data - [ example] ( samples/10-exceptions-recovery.cfc ) @Brad
152
- * [ ] [ Exercise 03] ( exercises/03-exceptions.cfc )
153
- * [ Solution 03] ( solutions/03-exceptions.cfc )
149
+ - [ ] Everybody has problems, our code has them too, sometimes...
150
+ - [ ] Let's review the promises [ data/error tracks] ( samples/04-cbfutures-stages.md )
151
+ - [ ] [ Dealing with Exceptions] ( samples/10-exceptions.cfc )
152
+ - [ ] Built-in logging - [ example] ( samples/10-exceptions-logging.cfc ) @Brad
153
+ - [ ] ` handle ` methods - both results and exceptions - [ example] ( samples/10-exceptions-handle.cfc ) @Brad
154
+ - [ ] [ Custom logging] ( samples/10-exceptions-custom-logging.cfc ) @Brad
155
+ - [ ] Recovering with data - [ example] ( samples/10-exceptions-recovery.cfc ) @Brad
156
+ - [ ] [ Exercise 03] ( exercises/03-exceptions.cfc )
157
+ - [ Solution 03] ( solutions/03-exceptions.cfc )
154
158
155
159
### Executors - Be the Manager
156
160
157
161
> Luis
158
162
159
- * [ ] [ Thread of execution] ( samples/11-nb-future.cfc )
160
- * [ ] [ Changing the pool] ( samples/12-custom-pool.cfc )
161
- * [ ] Register many different [ types of executors/pool] ( samples/13-cached-pool.cfc )
162
- * [ ] ` Fixed ` : Control the amount of threads, cpu intensive, io intensive
163
- * [ ] ` Single ` : A processing queue FIFO
164
- * [ ] ` Cached ` : Ever expanding demand queue
165
- * [ ] ` Scheduled ` : Scheduled Tasks
166
- * [ ] [ Checking status reinforcements] ( samples/09-statuschecks.cfc )
167
- * [ ] Shutdowns and awaiting terminations - [ example] ( samples/14-shutdown-terminations.cfc ) @Brad
168
- * [ ] Killing tasks? really? How?
169
- * [ ] [ Exercise 04] ( exercises/04-executors.cfc )
170
- * [ Solution 04] ( solutions/04-executors.cfc )
163
+ - [ ] [ Thread of execution] ( samples/11-nb-future.cfc )
164
+ - [ ] [ Changing the pool] ( samples/12-custom-pool.cfc )
165
+ - [ ] Register many different [ types of executors/pool] ( samples/13-cached-pool.cfc )
166
+ - [ ] ` Fixed ` : Control the amount of threads, cpu intensive, io intensive
167
+ - [ ] ` Single ` : A processing queue FIFO
168
+ - [ ] ` Cached ` : Ever expanding demand queue
169
+ - [ ] ` Scheduled ` : Scheduled Tasks
170
+ - [ ] [ Checking status reinforcements] ( samples/09-statuschecks.cfc )
171
+ - [ ] Shutdowns and awaiting terminations - [ example] ( samples/14-shutdown-terminations.cfc ) @Brad
172
+ - [ ] Killing tasks? really? How?
173
+ - [ ] [ Exercise 04] ( exercises/04-executors.cfc )
174
+ - [ Solution 04] ( solutions/04-executors.cfc )
171
175
172
176
### Parallel Tasks
173
177
174
178
> Brad
175
179
176
- * https://www.callicoder.com/java-8-completablefuture-tutorial/
177
- * [ Combining Futures] ( samples/15-combine.cfc )
178
- * Very much like a ` reduce() ` operations
179
- * Remember this: 1-1 operation
180
- * [ Composing Futures] ( samples/16-compose.cfc )
181
- * Monadic design pattern (https://medium.com/thg-tech-blog/monad-design-**pattern**-in-java-3391d4095b3f )
182
- * Hmm: 2-1 Operation, future of futures!
183
- * [ ] Working with multiple futures
184
- * [ Racing Futures] ( samples/17-anyOf.cfc )
185
- * [ All Futures] ( samples/18-all.cfc )
186
- * [ All futures Modified] ( samples/19-allapply.cfc )
187
- * [ ] [ Exercise 05] ( exercises/05-parallel-tasks.cfc )
188
- * [ Solution 05] ( solutions/05-parallel-tasks.cfc )
180
+ - https://www.callicoder.com/java-8-completablefuture-tutorial/
181
+ - [ Combining Futures] ( samples/15-combine.cfc )
182
+ - Very much like a ` reduce() ` operations
183
+ - Remember this: 1-1 operation
184
+ - [ Composing Futures] ( samples/16-compose.cfc )
185
+ - Monadic design pattern (https://medium.com/thg-tech-blog/monad-design-**pattern**-in-java-3391d4095b3f )
186
+ - Hmm: 2-1 Operation, future of futures!
187
+ - [ ] Working with multiple futures
188
+ - [ Racing Futures] ( samples/17-anyOf.cfc )
189
+ - [ All Futures] ( samples/18-all.cfc )
190
+ - [ All futures Modified] ( samples/19-allapply.cfc )
191
+ - [ ] [ Exercise 05] ( exercises/05-parallel-tasks.cfc )
192
+ - [ Solution 05] ( solutions/05-parallel-tasks.cfc )
189
193
190
194
191
195
### Q&A
0 commit comments