MCPcopy Create free account
hub / github.com/JordanCoin/codemap / runWithTimeout

Function runWithTimeout

cmd/hooks.go:158–174  ·  view source on GitHub ↗
(hookName string, timeout time.Duration, fn func() error)

Source from the content-addressed store, hash-verified

156}
157
158func 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
176func HookTimeoutFromEnv(getenv func(string) string) time.Duration {
177 if getenv == nil {

Callers 2

TestRunWithTimeoutFunction · 0.85
RunHookWithTimeoutFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestRunWithTimeoutFunction · 0.68