更新框架
This commit is contained in:
1 parent
ef50fa0620
commit
84b28f9672
72 files changed
+2222
-282
No files matched your search
@@ -0,0 +1,25 @@
|
||||
// 摘自 MediatR 14.2.0,许可声明与修改记录见 LICENSE.md 和 UPSTREAM.md。
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MAX.Notification.NotificationPublishers;
|
||||
|
||||
/// <summary>
|
||||
/// 在循环中依次调用并等待各通知处理器:
|
||||
/// <code>
|
||||
/// foreach (var handler in handlers) {
|
||||
/// await handler(notification, cancellationToken);
|
||||
/// }
|
||||
/// </code>
|
||||
/// </summary>
|
||||
public class ForeachAwaitPublisher : INotificationPublisher
|
||||
{
|
||||
public async Task Publish(IEnumerable<NotificationHandlerExecutor> handlerExecutors, INotification notification, CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (var handler in handlerExecutors)
|
||||
{
|
||||
await handler.HandlerCallback(notification, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 摘自 MediatR 14.2.0,许可声明与修改记录见 LICENSE.md 和 UPSTREAM.md。
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MAX.Notification.NotificationPublishers;
|
||||
|
||||
/// <summary>
|
||||
/// 使用 Task.WhenAll 等待通知处理器任务集合:
|
||||
/// <code>
|
||||
/// var tasks = handlers
|
||||
/// .Select(handler => handler.Handle(notification, cancellationToken))
|
||||
/// .ToList();
|
||||
///
|
||||
/// return Task.WhenAll(tasks);
|
||||
/// </code>
|
||||
/// </summary>
|
||||
public class TaskWhenAllPublisher : INotificationPublisher
|
||||
{
|
||||
public Task Publish(IEnumerable<NotificationHandlerExecutor> handlerExecutors, INotification notification, CancellationToken cancellationToken)
|
||||
{
|
||||
var tasks = handlerExecutors
|
||||
.Select(handler => handler.HandlerCallback(notification, cancellationToken))
|
||||
.ToArray();
|
||||
|
||||
return Task.WhenAll(tasks);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user