Skip to content

Марченко Максим ДЗ 2#55

Open
maks-march wants to merge 4 commits intokontur-courses:masterfrom
maks-march:homework
Open

Марченко Максим ДЗ 2#55
maks-march wants to merge 4 commits intokontur-courses:masterfrom
maks-march:homework

Conversation

@maks-march
Copy link
Copy Markdown

No description provided.

.Select(address => CallRequest(address, query))
.ToList();

var timeoutTask = Task.Delay(timeout).ContinueWith<string>(_ => throw new TimeoutException());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

По-хорошему timeoutTask бы создать до всех CallRequest. Иначе выходит, что запросы уже какое-то время как отправлены

runningTasks.Remove(timeoutTask);

timeout -= sw.Elapsed;
if (completedTask == timeoutTask)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Если реплики будут тормозить, то соответствующие таски так и останутся в runningTasks, и статистика для них не обновится

var timeoutTask = Task.Delay(replicaTimeout).ContinueWith<string>(_ => throw new TimeoutException());
runningTasks.Add(task, address);
runningTasks.Add(timeoutTask, "timeout");
var sw = Stopwatch.StartNew();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Здесь timeoutTask и Stopwatch тоже лучше перед CallRequest делать

var replicaTimeout = timeout / (ReplicaAddresses.Length - i);
var address = orderedReplicas[i];
var task = CallRequest(address, query);
var timeoutTask = Task.Delay(replicaTimeout);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

timeout и replicaTimeout могут оказаться отрицательными. Task.Delay может или выбросить исключение, или, с маленьким шансом, превратиться в никогда не заканчивающуюся таску

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants