35 lines
2.1 KiB
C#
35 lines
2.1 KiB
C#
|
|
// Copyright (c) The Geekeey Authors
|
||
|
|
// SPDX-License-Identifier: EUPL-1.2
|
||
|
|
|
||
|
|
#pragma warning disable CA1711
|
||
|
|
#pragma warning disable CA1716
|
||
|
|
|
||
|
|
namespace Geekeey.Request.Dispatcher;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Represents a behavior in the request pipeline, allowing interception, modification,
|
||
|
|
/// or chaining of asynchronous stream requests and responses.
|
||
|
|
/// </summary>
|
||
|
|
/// <typeparam name="TRequest">The type of the request being processed. Must implement <see cref="IStreamRequest{TResponse}"/>.</typeparam>
|
||
|
|
/// <typeparam name="TResponse">The type of the response produced by the implementing request handler.</typeparam>
|
||
|
|
public interface IStreamRequestBehavior<in TRequest, TResponse> where TRequest : IStreamRequest<TResponse>
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// Handles the asynchronous processing of a request, allowing behavior customization
|
||
|
|
/// such as interception, modification, or chaining of the request and its response.
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="request">The request instance being processed.</param>
|
||
|
|
/// <param name="next">The next delegate in the pipeline to execute after the custom behavior.</param>
|
||
|
|
/// <param name="cancellationToken">A token to monitor for cancellation requests.</param>
|
||
|
|
/// <returns>An asynchronous stream of <typeparamref name="TResponse"/> representing the processed response.</returns>
|
||
|
|
IAsyncEnumerable<TResponse> HandleAsync(TRequest request, StreamHandlerDelegate<TResponse> next, CancellationToken cancellationToken);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Represents the delegate responsible for handling asynchronous requests in a pipeline.
|
||
|
|
/// </summary>
|
||
|
|
/// <typeparam name="TResponse">The type of the response produced by the implementing request handler.</typeparam>
|
||
|
|
/// <param name="request">The asynchronous request being processed.</param>
|
||
|
|
/// <param name="cancellationToken">A token for monitoring cancellation requests.</param>
|
||
|
|
/// <returns>An asynchronous stream of responses of type <typeparamref name="TResponse"/>.</returns>
|
||
|
|
public delegate IAsyncEnumerable<TResponse> StreamHandlerDelegate<TResponse>(IStreamRequest<TResponse> request, CancellationToken cancellationToken);
|