Interface ICancellationStrategy
- Namespace
- StreamJsonRpc
- Assembly
- StreamJsonRpc.dll
Defines an extensibility point by which RPC methods may be canceled using CancellationToken.
public interface ICancellationStrategy
Remarks
A cancellation strategy can be set on the CancellationStrategy property.
The default implementation is defined by StreamJsonRpc.StandardCancellationStrategy.
Implementations must be thread-safe.
Methods
CancelOutboundRequest(RequestId)
Translates a canceled CancellationToken that was used in an outbound RPC request into terms that the RPC server can understand.
void CancelOutboundRequest(RequestId requestId)
Parameters
requestId
RequestIdThe ID of the canceled request.
Remarks
Every call to this method is followed by a subsequent call to OutboundRequestEnded(RequestId).
IncomingRequestEnded(RequestId)
Cleans up any state associated with an earlier IncomingRequestStarted(RequestId, CancellationTokenSource) call.
void IncomingRequestEnded(RequestId requestId)
Parameters
requestId
RequestIdThe ID of the request that has been fulfilled.
Remarks
Implementations are expected to release memory allocated by a prior call to IncomingRequestStarted(RequestId, CancellationTokenSource). This method should not dispose of the CancellationTokenSource received previously as JsonRpc owns its lifetime.
IncomingRequestStarted(RequestId, CancellationTokenSource)
Associates the RequestId from an incoming request with the CancellationTokenSource that is used for the CancellationToken passed to that RPC method so it can be canceled later.
void IncomingRequestStarted(RequestId requestId, CancellationTokenSource cancellationTokenSource)
Parameters
requestId
RequestIdThe ID of the incoming request.
cancellationTokenSource
CancellationTokenSourceA means to cancel the CancellationToken that will be used when invoking the RPC server method.
Remarks
Implementations are expected to store the arguments in a dictionary so the implementing strategy can cancel it when the trigger occurs. The trigger is outside the scope of this interface and will vary by implementation.
OutboundRequestEnded(RequestId)
Cleans up any state associated with an earlier CancelOutboundRequest(RequestId) call.
void OutboundRequestEnded(RequestId requestId)
Parameters
requestId
RequestIdThe ID of the canceled request.
Remarks
This method is invoked by JsonRpc when the response to a canceled request has been received. It may be invoked for requests for which a prior call to CancelOutboundRequest(RequestId) was not made, due to timing. But it should never be invoked concurrently with CancelOutboundRequest(RequestId) for the same RequestId.