1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-12-03 23:19:17 +02:00
Files
imgproxy/timer.go

34 lines
558 B
Go
Raw Normal View History

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