/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit/Middleware/ContextFilter.cs
44 строки
1 KB
Chris Patterson
Integration of all external packages into MassTransit, split out into Abstractions, Middleware, and the core MassTransit assembly.
22 янв 2022, 18:24
22 янв 2022, 18:24
b5b4f50
Код
Авторство
О чём код?
namespace MassTransit.Middleware { using System; using System.Threading.Tasks; /// <summary> /// A content filter applies a delegate to the message context, and uses the result to either accept the message /// or discard it. /// </summary> /// <typeparam name="TContext"></typeparam> public class ContextFilter<TContext> : IFilter<TContext> where TContext : class, PipeContext { readonly Func<TContext, Task<bool>> _filter; public ContextFilter(Func<TContext, Task<bool>> filter) { _filter = filter; } public Task Send(TContext context, IPipe<TContext> next) { Task<bool> filterTask = _filter(context); if (filterTask.Status == TaskStatus.RanToCompletion && filterTask.Result) return next.Send(context); async Task SendAsync() { var accept = await filterTask.ConfigureAwait(false); if (accept) await next.Send(context).ConfigureAwait(false); } return SendAsync(); } public void Probe(ProbeContext context) { context.CreateFilterScope("context"); } } }