Skip to content
This repository was archived by the owner on Jan 16, 2021. It is now read-only.

Commit dd7450b

Browse files
committed
Merge pull request #22 from pavanka/timeouts
add timeout to get supported version
2 parents 48a4ee6 + a94b0d8 commit dd7450b

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

utils.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"regexp"
99
"strconv"
1010
"strings"
11+
"time"
1112

1213
"github.com/facebookgo/errgroup"
1314
"github.com/facebookgo/parse"
@@ -116,14 +117,27 @@ func checkIfSupported(e *env, version string) (string, error) {
116117
URL: &url.URL{Path: "supported", RawQuery: v.Encode()},
117118
}
118119

119-
var res struct {
120-
Warning string `json:"warning"`
120+
type result struct {
121+
warning string
122+
err error
121123
}
122124

123-
if _, err := e.ParseAPIClient.Do(req, nil, &res); err != nil {
124-
return "", stackerr.Wrap(err)
125+
timeout := make(chan *result, 1)
126+
go func() {
127+
var res struct {
128+
Warning string `json:"warning"`
129+
}
130+
_, err := e.ParseAPIClient.Do(req, nil, &res)
131+
timeout <- &result{warning: res.Warning, err: err}
132+
}()
133+
134+
select {
135+
case res := <-timeout:
136+
return res.warning, stackerr.Wrap(res.err)
137+
case <-time.After(time.Duration(500) * time.Millisecond):
138+
return "", nil
125139
}
126-
return res.Warning, nil
140+
return "", nil
127141
}
128142

129143
// errorString returns the error string with our without the stack trace

0 commit comments

Comments
 (0)