public class CancellationTokenSource
extends java.lang.Object
implements java.io.Closeable
CancellationToken
that it should be canceled. To create a
CancellationToken
first create a CancellationTokenSource
then call
getToken()
to retrieve the token for the source.CancellationToken
,
getToken()
Constructor and Description |
---|
CancellationTokenSource()
Create a new
CancellationTokenSource . |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancels the token if it has not already been cancelled.
|
void |
cancelAfter(long delay)
Schedules a cancel operation on this
CancellationTokenSource after the specified number of milliseconds. |
void |
close() |
CancellationToken |
getToken() |
boolean |
isCancellationRequested() |
java.lang.String |
toString() |
public CancellationTokenSource()
CancellationTokenSource
.public boolean isCancellationRequested()
true
if cancellation has been requested for this CancellationTokenSource
.public CancellationToken getToken()
public void cancel()
public void cancelAfter(long delay)
CancellationTokenSource
after the specified number of milliseconds.delay
- The number of milliseconds to wait before completing the returned task. If delay is 0
the cancel is executed immediately. If delay is -1
any scheduled cancellation is stopped.public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public java.lang.String toString()
toString
in class java.lang.Object