-
Notifications
You must be signed in to change notification settings - Fork 22
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
base: master
Are you sure you want to change the base?
Conversation
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мертвый код
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так это намеренное замедление функции, чтобы по логике кэш получать
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это неправильно, у тебя же выше блокирующие вызовы на чтение из БД и кэша, поэтому никакого таймаута не будет
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так это синхронное получение данных из источников, предполагается, что в select будет обрабатываться timeout. А как правильно должно быть?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Словами не объяснишь - на кажжый синхронный вызов должна быть запущена горутина по очереди, а не параллельно и главное уметь ее поутшить при пробивании таймаута
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Понимаю к чему клонишь, но можешь примерно кодом набросать, чтобы было единое виденье
// GetData возвращает данные из getter, страхуя кешом
// в случае ошибки. Проблема: getter может отвечать
// очень долго.
// Задача: в случае ответа дольше timeout отдавать кеш,
// и правильно обработать кейс, когда getter всегда отвечает долго.