forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mqtt_timeout.go
37 lines (32 loc) · 908 Bytes
/
mqtt_timeout.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 provider
// TimeoutHandler is a wrapper for a Getter that times out after a given duration
type TimeoutHandler struct {
ticker func() (string, error)
}
func NewTimeoutHandler(ticker func() (string, error)) *TimeoutHandler {
return &TimeoutHandler{ticker}
}
func (h *TimeoutHandler) BoolGetter(g func() (bool, error)) func() (bool, error) {
return func() (val bool, err error) {
if val, err = g(); err == nil {
_, err = h.ticker()
}
return val, err
}
}
func (h *TimeoutHandler) FloatGetter(g func() (float64, error)) func() (float64, error) {
return func() (val float64, err error) {
if val, err = g(); err == nil {
_, err = h.ticker()
}
return val, err
}
}
func (h *TimeoutHandler) StringGetter(g func() (string, error)) func() (string, error) {
return func() (val string, err error) {
if val, err = g(); err == nil {
_, err = h.ticker()
}
return val, err
}
}