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
TResponseThe 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
correlationIdGuidThe correlation ID.
timeoutTimeSpanThe timeout duration.
cancellationTokenCancellationTokenCancellation token.
onTimeoutAction<Guid>Callback when timeout occurs.
Properties
CorrelationId
Gets the correlation ID for this request.
public Guid CorrelationId { get; }
Property Value
CreatedAt
Gets the timestamp when the request was created.
public DateTimeOffset CreatedAt { get; }
Property Value
IsCompleted
Gets a value indicating whether the request has completed.
public bool IsCompleted { get; }
Property Value
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
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
exceptionExceptionThe 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
responseTResponseThe 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
responseIResponseMessageThe response message.
Returns
- bool
True if the context was completed; false if already completed or type mismatch.