Skip to content

Commit 868155a

Browse files
committed
Example for multiple arguments and returns
1 parent 9f088d0 commit 868155a

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,24 @@ func main() {
5757
fmt.Println("sum: ", d) // sum: 5
5858
}
5959
```
60+
61+
## Multiple arguments and returns
62+
```go
63+
func main() {
64+
65+
t := promise.
66+
New(func(resolve promise.Accept, reject promise.Decline) {
67+
resolve(1)
68+
}).
69+
Then(func(n int) (int, int, float64, promise.Promise) {
70+
return n, 2, 3.5, promise.Resolve(4.5)
71+
}).
72+
Then(func(a, b int, c, d float64) int {
73+
return int(float64(a) + float64(b) + c + d)
74+
})
75+
76+
d := t.Result()
77+
78+
fmt.Println("total: ", d)
79+
}
80+
```

examples/multiple-args/main.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/samuelngs/go-promise"
7+
)
8+
9+
func main() {
10+
11+
t := promise.
12+
New(func(resolve promise.Accept, reject promise.Decline) {
13+
resolve(1)
14+
}).
15+
Then(func(n int) (int, int, float64, promise.Promise) {
16+
return n, 2, 3.5, promise.Resolve(4.5)
17+
}).
18+
Then(func(a, b int, c, d float64) int {
19+
return int(float64(a) + float64(b) + c + d)
20+
})
21+
22+
d := t.Result()
23+
24+
fmt.Println("total: ", d)
25+
}

0 commit comments

Comments
 (0)