mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-29 08:22:11 +02:00
33 lines
508 B
Go
33 lines
508 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type timer struct {
|
|
StartTime time.Time
|
|
Timer <-chan time.Time
|
|
}
|
|
|
|
func startTimer(dt time.Duration) *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)
|
|
}
|