-
Notifications
You must be signed in to change notification settings - Fork 0
/
allsettled.go
37 lines (33 loc) · 934 Bytes
/
allsettled.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
package gromise
type AllSettledValue struct {
Status GromiseStatus
Value interface{}
Reason error
}
type AllSettledResult struct {
finishedCh chan bool
timeoutCh chan bool
timeout bool
values []*AllSettledValue
}
func newAllSettledResult() *AllSettledResult {
result := &AllSettledResult{
finishedCh: make(chan bool, 1),
timeoutCh: make(chan bool, 1),
timeout: false,
values: []*AllSettledValue{},
}
return result
}
// Run all the functions in parallel and wait for all of them to finish.
// Notice that gromise can't terminate the goroutines since it's the Golang's
// limitation, so if there are any goroutines that are still running after
// the timeout, they will be left running, which may cause goroutine leak.
func (r *AllSettledResult) Await() ([]*AllSettledValue, error) {
select {
case <-r.finishedCh:
return r.values, nil
case <-r.timeoutCh:
return r.values, ErrorTimeout
}
}