(hookName string, timeout time.Duration, fn func() error)
| 156 | } |
| 157 | |
| 158 | func runWithTimeout(hookName string, timeout time.Duration, fn func() error) error { |
| 159 | if timeout <= 0 { |
| 160 | return fn() |
| 161 | } |
| 162 | |
| 163 | done := make(chan error, 1) |
| 164 | go func() { |
| 165 | done <- fn() |
| 166 | }() |
| 167 | |
| 168 | select { |
| 169 | case err := <-done: |
| 170 | return err |
| 171 | case <-time.After(timeout): |
| 172 | return &HookTimeoutError{Hook: hookName, Timeout: timeout} |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | func HookTimeoutFromEnv(getenv func(string) string) time.Duration { |
| 177 | if getenv == nil { |
no outgoing calls