Table of Contents

Class CorrelationContext<TResponse>

Namespace
DotCompute.Abstractions.Messaging
Assembly
DotCompute.Abstractions.dll

Represents a pending correlation context for a request awaiting a response.

public sealed class CorrelationContext<TResponse> : ICorrelationContextBase, IDisposable where TResponse : IResponseMessage

Type Parameters

TResponse

The expected response type.

Inheritance
CorrelationContext<TResponse>
Implements
Inherited Members
Extension Methods

Constructors

CorrelationContext(Guid, TimeSpan, CancellationToken, Action<Guid>?)

Creates a new correlation context.

public CorrelationContext(Guid correlationId, TimeSpan timeout, CancellationToken cancellationToken, Action<Guid>? onTimeout = null)

Parameters

correlationId Guid

The correlation ID.

timeout TimeSpan

The timeout duration.

cancellationToken CancellationToken

Cancellation token.

onTimeout Action<Guid>

Callback when timeout occurs.

Properties

CorrelationId

Gets the correlation ID for this request.

public Guid CorrelationId { get; }

Property Value

Guid

CreatedAt

Gets the timestamp when the request was created.

public DateTimeOffset CreatedAt { get; }

Property Value

DateTimeOffset

IsCompleted

Gets a value indicating whether the request has completed.

public bool IsCompleted { get; }

Property Value

bool

ResponseTask

Gets a task that completes when the response arrives or times out.

public Task<TResponse> ResponseTask { get; }

Property Value

Task<TResponse>

Timeout

Gets the timeout duration.

public TimeSpan Timeout { get; }

Property Value

TimeSpan

Methods

Dispose()

Disposes the correlation context and its resources.

public void Dispose()

TrySetCanceled()

Cancels the pending request.

public bool TrySetCanceled()

Returns

bool

True if the context was cancelled; false if already completed.

TrySetException(Exception)

Completes the context with an exception.

public bool TrySetException(Exception exception)

Parameters

exception Exception

The exception.

Returns

bool

True if the context was completed; false if already completed.

TrySetResult(TResponse)

Completes the context with a response.

public bool TrySetResult(TResponse response)

Parameters

response TResponse

The response message.

Returns

bool

True if the context was completed; false if already completed.

TrySetResultUntyped(IResponseMessage)

Attempts to complete the context with a response message.

public bool TrySetResultUntyped(IResponseMessage response)

Parameters

response IResponseMessage

The response message.

Returns

bool

True if the context was completed; false if already completed or type mismatch.