Package com.grapecity.documents.excel
Class CancellationTokenSource
java.lang.Object
com.grapecity.documents.excel.CancellationTokenSource
- All Implemented Interfaces:
AutoCloseable
A
CancellationTokenSource allows you to issue cancellation requests to one or more methods.To use a token source: - Create a token source.
- Attach the token to one or more operations by passing the return value of
getToken()as parameter. - Later, you can cancel the associated operations by calling
cancel()on this token source.
This class is thread safe.
- API Note:
- You must call the
close()method when you don't need to use it anymore.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Initiates cancel request.voidcancelAfter(Duration delay) Schedules a cancel operation on thisCancellationTokenSourceafter the specified time span.voidclose()Closes the resource and performs cleanup operations.getToken()Returns a token associated with thisCancellationTokenSource.
-
Constructor Details
-
CancellationTokenSource
public CancellationTokenSource()
-
-
Method Details
-
cancel
public void cancel()Initiates cancel request. All operations that have been associated with this token will be cancelled.It is assumed that the consumers of
getToken()will do 'best-effort' attempt to perform cancellation.This method returns immediately and if the cancellation is successful the cancelled operation will throwCancellationException. -
cancelAfter
Schedules a cancel operation on thisCancellationTokenSourceafter the specified time span.- Parameters:
delay- The time span to wait before canceling thisCancellationTokenSource. This value can't be null.
-
getToken
Returns a token associated with thisCancellationTokenSource.- Returns:
- The cancellation token. Always returns the same instance.
-
close
Closes the resource and performs cleanup operations.- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-