Table of Contents

Class MessageAggregator<TResponse, TResult>

Namespace
DotCompute.Core.Messaging
Assembly
DotCompute.Core.dll

Aggregates responses from multiple requests into a single result.

public sealed class MessageAggregator<TResponse, TResult> : IMessageAggregator<TResult>, IAsyncDisposable where TResponse : IResponseMessage

Type Parameters

TResponse

The response type.

TResult

The aggregated result type.

Inheritance
MessageAggregator<TResponse, TResult>
Implements
Inherited Members

Constructors

MessageAggregator(int, Func<IReadOnlyList<TResponse>, TResult>, AggregationOptions, ILogger, CancellationToken)

Creates a new message aggregator.

public MessageAggregator(int expectedCount, Func<IReadOnlyList<TResponse>, TResult> aggregateFunc, AggregationOptions options, ILogger logger, CancellationToken cancellationToken = default)

Parameters

expectedCount int

Number of expected responses.

aggregateFunc Func<IReadOnlyList<TResponse>, TResult>

Function to aggregate responses.

options AggregationOptions

Aggregation options.

logger ILogger

Logger for diagnostics.

cancellationToken CancellationToken

Cancellation token.

Properties

AggregatedResult

Gets a task that completes when aggregation is complete or times out.

public Task<TResult> AggregatedResult { get; }

Property Value

Task<TResult>

ExpectedCount

Gets the number of expected responses.

public int ExpectedCount { get; }

Property Value

int

IsComplete

Gets a value indicating whether all expected responses have been received.

public bool IsComplete { get; }

Property Value

bool

ReceivedCount

Gets the number of received responses.

public int ReceivedCount { get; }

Property Value

int

Methods

AddResponseAsync<TResponseInput>(TResponseInput, CancellationToken)

Adds a response to the aggregation.

public Task<bool> AddResponseAsync<TResponseInput>(TResponseInput response, CancellationToken cancellationToken = default) where TResponseInput : IResponseMessage

Parameters

response TResponseInput

The response to add.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<bool>

True if aggregation is complete after adding.

Type Parameters

TResponseInput

Cancel()

Cancels the aggregation and completes with partial results.

public void Cancel()

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

MarkFailed(Guid, Exception)

Marks a specific request as failed.

public void MarkFailed(Guid correlationId, Exception exception)

Parameters

correlationId Guid

The correlation ID of the failed request.

exception Exception

The exception that occurred.