[]
        
(Showing Draft Content)

CancellationTokenSource

Class CancellationTokenSource

java.lang.Object
com.grapecity.documents.excel.CancellationTokenSource
All Implemented Interfaces:
AutoCloseable

public class CancellationTokenSource extends Object implements 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 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 throw CancellationException.

    • cancelAfter

      public void cancelAfter(Duration delay)
      Schedules a cancel operation on this CancellationTokenSource after the specified time span.
      Parameters:
      delay - The time span to wait before canceling this CancellationTokenSource. This value can't be null.
    • getToken

      public CancellationToken getToken()
      Returns a token associated with this CancellationTokenSource.
      Returns:
      The cancellation token. Always returns the same instance.
    • close

      public void close() throws Exception
      Closes the resource and performs cleanup operations.
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception