-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (45 loc) · 1020 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"sync"
)
type outcome struct {
app string
code int
msg string
}
type overallResult struct {
a outcome
b outcome
}
func (r overallResult) allValid() bool {
ok := r.a.code == 0 && r.b.code == 0
return ok
}
func main() {
var res = new(overallResult)
var wg sync.WaitGroup
wg.Add(2)
result := make(chan outcome)
go checkIban(&wg, result)
go checkAccount(&wg, result)
res.a, res.b = <-result, <-result
wg.Wait()
close(result)
fmt.Println(res)
fmt.Println("Is valid", res.allValid())
fmt.Println("Both goroutines returned values")
}
func checkIban(wg *sync.WaitGroup, result chan outcome) {
defer wg.Done()
returnValue := outcome{app: "a", code: 0}
result <- returnValue
fmt.Println("checkIban completed")
}
func checkAccount(wg *sync.WaitGroup, result chan outcome) {
defer wg.Done()
//returnValue := outcome{app: "b", code: 0}
returnValue := outcome{app: "b", code: 1, msg: "Conto inesistente"}
result <- returnValue
fmt.Println("checkAccount completed")
}