Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code for review #3

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Code for review #3

wants to merge 12 commits into from

Conversation

caligonox
Copy link

// GetData возвращает данные из getter, страхуя кешом
// в случае ошибки. Проблема: getter может отвечать
// очень долго.

// Задача: в случае ответа дольше timeout отдавать кеш,
// и правильно обработать кейс, когда getter всегда отвечает долго.

get_data.go Outdated
@@ -15,53 +16,34 @@ var (
const timeout = time.Second

func getter(key string) (any, error) {
// time.Sleep(1 * time.Microsecond)
// time.Sleep(2 * time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мертвый код

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так это намеренное замедление функции, чтобы по логике кэш получать

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сейчас это мертвый код в комментариях)

return nil, err
default:
}
select {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это неправильно, у тебя же выше блокирующие вызовы на чтение из БД и кэша, поэтому никакого таймаута не будет

Copy link
Author

@caligonox caligonox Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так это синхронное получение данных из источников, предполагается, что в select будет обрабатываться timeout. А как правильно должно быть?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Словами не объяснишь - на кажжый синхронный вызов должна быть запущена горутина по очереди, а не параллельно и главное уметь ее поутшить при пробивании таймаута

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Понимаю к чему клонишь, но можешь примерно кодом набросать, чтобы было единое виденье

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants