1package aws 2 3import ( 4 "time" 5) 6 7// SleepWithContext will wait for the timer duration to expire, or the context 8// is canceled. Which ever happens first. If the context is canceled the Context's 9// error will be returned. 10// 11// Expects Context to always return a non-nil error if the Done channel is closed. 12func SleepWithContext(ctx Context, dur time.Duration) error { 13 t := time.NewTimer(dur) 14 defer t.Stop() 15 16 select { 17 case <-t.C: 18 break 19 case <-ctx.Done(): 20 return ctx.Err() 21 } 22 23 return nil 24} 25