@@ -181,8 +181,8 @@ p := Promise.Create(func(resolve Promise.Callback, reject Promise.Callback) {
181
181
182
182
183
183
184
- * Want bunch of Promises executed at once 👀 Note:
185
- These are position aware nothing is jumbled
184
+ * Want bunch of Promises executed at once 👀
185
+ Note: These are position aware nothing is jumbled
186
186
``` golang
187
187
188
188
@@ -255,9 +255,14 @@ for value := range Promise.AsyncGenerator(promises) {
255
255
fmt.Println (value)
256
256
}
257
257
258
- ```
258
+ ```
259
+
260
+
261
+
262
+
259
263
260
- * My Map is all parallel , can I have a reduce, that pipelines with request delays ? 👩⚖️
264
+
265
+ * My Map is all parallel , can I have a reduce, that pipelines with request delays ? 👩⚖️
261
266
Yes the Reduce provided here internally uses AsyncGenerator to grab data and quicly
262
267
launch promise task to to luanch reducer for each data. Effectively pipelining with
263
268
the promises passsed to it.
@@ -269,17 +274,19 @@ for value := range Promise.AsyncGenerator(promises) {
269
274
promises := make ([]*Promise.Promise , 3 )
270
275
for i := 0 ; i < len (promises); i++ {
271
276
index := i
272
- promises[i] = Promise .Create (func (resolve Promise.Callback , reject Promise.Callback ) {
273
- time.Sleep (time.Duration (index)*time.Second + time.Duration (10 ))
274
- resolve (index + 1 )
277
+ promises[i] = Promise .Create (
278
+ func (resolve Promise .Callback , reject Promise .Callback ) {
279
+ time.Sleep (time.Duration (index)*time.Second + time.Duration (10 ))
280
+ resolve (index + 1 )
275
281
})
276
282
}
277
283
278
- value := Promise .Reduce (promises, func (index int , acci interface {}, valuei interface {}) interface {} {
279
- acc , _ := acci.(int )
280
- value , _ := valuei.(int )
281
- acc = value + acc
282
- return acc
284
+ value := Promise .Reduce (promises,
285
+ func (index int , acci interface {}, valuei interface {}) interface {} {
286
+ acc , _ := acci.(int )
287
+ value , _ := valuei.(int )
288
+ acc = value + acc
289
+ return acc
283
290
}, 0 ).Finally (nil )
284
291
285
292
```
0 commit comments