-
Notifications
You must be signed in to change notification settings - Fork 1
/
timeout.go
36 lines (28 loc) · 908 Bytes
/
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
package lemon
import (
"errors"
"time"
)
const (
// DefaultTimeout is the default (and maximum) amount of time the engine will wait for a hook to gracefully shutdown.
DefaultTimeout = 5 * time.Second
)
var (
// ErrTimeout is returned when given timeout is negative or equal zero.
ErrTimeout = errors.New("invalid timeout: must be positive and not equal zero")
)
// Timeout define the maximum amount of time the engine will wait for hooks to gracefully shut down.
func (e *Engine) Timeout() time.Duration {
return e.timeout
}
// Timeout sets the maximum amount of time the engine will wait for hooks to gracefully shut down.
// After this timeout, hooks will be forcefully shut down by destroying underlying goroutines.
func Timeout(timeout time.Duration) Option {
return wrapOption(func(e *Engine) error {
if timeout <= 0 {
return ErrTimeout
}
e.timeout = timeout
return nil
})
}