mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-24 08:12:38 +02:00
33 lines
521 B
Go
33 lines
521 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type timer struct {
|
|
StartTime time.Time
|
|
Timer <-chan time.Time
|
|
}
|
|
|
|
func startTimer(dt time.Duration, info string) *timer {
|
|
return &timer{time.Now(), time.After(dt)}
|
|
}
|
|
|
|
func (t *timer) Check() {
|
|
select {
|
|
case <-t.Timer:
|
|
panic(t.TimeoutErr())
|
|
default:
|
|
// Go ahead
|
|
}
|
|
}
|
|
|
|
func (t *timer) TimeoutErr() imgproxyError {
|
|
return newError(503, fmt.Sprintf("Timeout after %v", t.Since()), "Timeout")
|
|
}
|
|
|
|
func (t *timer) Since() time.Duration {
|
|
return time.Since(t.StartTime)
|
|
}
|