Interface CancelationToken
Thread-safe cancelation signal for response stream producers.
Producers should check this token between expensive or blocking operations and stop producing when it becomes canceled. Soklet cancels the token when a streaming response can no longer continue, such as when the client disconnects, the server shuts down, the request HTTP version cannot support streaming, or a streaming timeout is reached.
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionThe underlying cancelation cause, if available.The cancelation reason, if cancelation has occurred.Is the associated operation canceled?Registers a callback that runs when the token is canceled.default voidThrows if the token has been canceled.
-
Method Details
-
isCanceled
-
getCancelationReason
The cancelation reason, if cancelation has occurred.- Returns:
- the cancelation reason, or
Optional.empty()if not canceled
-
getCancelationCause
The underlying cancelation cause, if available.- Returns:
- the underlying cause, or
Optional.empty()if no cause is available
-
onCancel
Registers a callback that runs when the token is canceled.The returned handle removes the callback when closed. If the token is already canceled, the callback may run before this method returns.
Callbacks run synchronously on the thread that performs cancelation. Keep callbacks fast and non-blocking; if cleanup may take meaningful time, dispatch it to an application-owned executor from the callback.
- Parameters:
callback- the callback to run on cancelation- Returns:
- a handle that removes the callback when closed
-
throwIfCanceled
Throws if the token has been canceled.- Throws:
StreamingResponseCanceledException- if canceled
-