2017-10-04 21:44:58 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type timer struct {
|
|
|
|
StartTime time.Time
|
|
|
|
Timer <-chan time.Time
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:21:43 +02:00
|
|
|
func startTimer(dt time.Duration, info string) *timer {
|
2018-03-19 10:58:52 +02:00
|
|
|
return &timer{time.Now(), time.After(dt)}
|
2017-10-04 21:44:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *timer) Check() {
|
|
|
|
select {
|
|
|
|
case <-t.Timer:
|
|
|
|
panic(t.TimeoutErr())
|
|
|
|
default:
|
|
|
|
// Go ahead
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *timer) TimeoutErr() imgproxyError {
|
2018-03-19 10:58:52 +02:00
|
|
|
return newError(503, fmt.Sprintf("Timeout after %v", t.Since()), "Timeout")
|
2017-10-04 21:44:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *timer) Since() time.Duration {
|
|
|
|
return time.Since(t.StartTime)
|
|
|
|
}
|