/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit.Abstractions/Util/ActiveRequest.cs
56 строк
1 KB
Chris Patterson
Fixed #5114 - Changed the request result limit for the EF Core Outbox Delivery service to scale up properly, Reworked the request rate algorithm to support delayed cancellation of in-flight requests.
20 апр 2024, 00:51
20 апр 2024, 00:51
53ac232
Код
Авторство
О чём код?
namespace MassTransit.Util { using System; using System.Threading; using System.Threading.Tasks; public struct ActiveRequest : IDisposable { readonly RequestRateAlgorithm _algorithm; readonly CancellationTokenRegistration _registration; readonly CancellationTokenSource _source; readonly TimeSpan _timeout; bool _completed; public readonly CancellationToken CancellationToken; public readonly int ResultLimit; public ActiveRequest(RequestRateAlgorithm algorithm, int resultLimit, CancellationToken cancellationToken, TimeSpan timeout) { _algorithm = algorithm; _timeout = timeout; _source = new CancellationTokenSource(); _registration = cancellationToken.Register(Callback, this); CancellationToken = _source.Token; ResultLimit = resultLimit; _completed = false; } public Task Complete(int count, CancellationToken cancellationToken = default) { _completed = true; return _algorithm.EndRequest(count, ResultLimit, cancellationToken); } public void Dispose() { _registration.Dispose(); _source.Dispose(); if (_completed) return; _algorithm.CancelRequest(ResultLimit); } void Callback(object? obj) { _source.CancelAfter(_timeout); } } }