Запрос к S3 завис. Реализуйте readWithTimeout(ch <-chan int, timeout time.Duration) (int, bool): читайте значение, но не дольше timeout; при таймауте — (0, false).
- Задача
- Решение
- Обсуждение
ReadWithTimeout: таймаут на чтение
GolangРешение
func readWithTimeout(ch <-chan int, timeout time.Duration) (int, bool) {
select {
case v := <-ch:
return v, true
case <-time.After(timeout):
return 0, false
}
}