DoWithTimeout: таймаут на операцию
Выгрузка не должна ждать вечно. Реализуйте doWithTimeout(ctx, f, timeout) error: WithTimeout, запустить f в горутине, select по ctx.Done().
Показать решение
GolangРешение
func doWithTimeout(ctx context.Context, f func(), timeout time.Duration) error {
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
done := make(chan struct{})
go func() {
f()
close(done)
}()
select {
case <-done:
return nil
case <-ctx.Done():
return ctx.Err()
}
}Записаться на разбор
10 000 ₽ · 60 минут · онлайн