sleep context
#Go
code:sleep_context.go
import (
"context"
"time"
)
func sleepContext(ctx context.Context, delay time.Duration) {
timer := time.NewTimer(delay)
select {
case <-ctx.Done():
if !timer.Stop() {
<-timer.C
}
case <-timer.C:
}
}