Skip to content

Commit

Permalink
fixed readme
Browse files Browse the repository at this point in the history
  • Loading branch information
rajatkb committed Oct 26, 2020
1 parent 14ddc42 commit dd4f912
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ p := Promise.Create(func(resolve Promise.Callback, reject Promise.Callback) {



* Want bunch of Promises executed at once 👀 Note:
These are position aware nothing is jumbled
* Want bunch of Promises executed at once 👀
Note: These are position aware nothing is jumbled
```golang


Expand Down Expand Up @@ -255,9 +255,14 @@ for value := range Promise.AsyncGenerator(promises) {
fmt.Println(value)
}

```
```





*My Map is all parallel , can I have a reduce, that pipelines with request delays ? 👩‍⚖️

* My Map is all parallel , can I have a reduce, that pipelines with request delays ? 👩‍⚖️
Yes the Reduce provided here internally uses AsyncGenerator to grab data and quicly
launch promise task to to luanch reducer for each data. Effectively pipelining with
the promises passsed to it.
Expand All @@ -269,17 +274,19 @@ for value := range Promise.AsyncGenerator(promises) {
promises := make([]*Promise.Promise, 3)
for i := 0; i < len(promises); i++ {
index := i
promises[i] = Promise.Create(func(resolve Promise.Callback, reject Promise.Callback) {
time.Sleep(time.Duration(index)*time.Second + time.Duration(10))
resolve(index + 1)
promises[i] = Promise.Create(
func(resolve Promise.Callback, reject Promise.Callback) {
time.Sleep(time.Duration(index)*time.Second + time.Duration(10))
resolve(index + 1)
})
}

value := Promise.Reduce(promises, func(index int, acci interface{}, valuei interface{}) interface{} {
acc, _ := acci.(int)
value, _ := valuei.(int)
acc = value + acc
return acc
value := Promise.Reduce(promises,
func(index int, acci interface{}, valuei interface{}) interface{} {
acc, _ := acci.(int)
value, _ := valuei.(int)
acc = value + acc
return acc
}, 0).Finally(nil)

```
Expand Down

0 comments on commit dd4f912

Please sign in to comment.