Android SDK Version
  • java.lang.Object
    • com.facebook.bolts.CancellationTokenSource
All Implemented Interfaces:
java.io.Closeable, java.lang.AutoCloseable

public class CancellationTokenSource
extends java.lang.Object
implements java.io.Closeable
Signals to a CancellationToken that it should be canceled. To create a CancellationToken first create a CancellationTokenSource then call getToken() to retrieve the token for the source.
Constructor Summary
Constructor and Description
CancellationTokenSource()
Create a new CancellationTokenSource.
Method Summary
Modifier and TypeMethod and Description
voidcancel()
Cancels the token if it has not already been cancelled.
voidcancelAfter(long delay)
Schedules a cancel operation on this CancellationTokenSource after the specified number of milliseconds.
voidclose() 
CancellationTokengetToken() 
booleanisCancellationRequested() 
java.lang.StringtoString() 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Constructor Detail

CancellationTokenSource

public CancellationTokenSource()
Create a new CancellationTokenSource.
Method Detail

isCancellationRequested

public boolean isCancellationRequested()
Returns:
true if cancellation has been requested for this CancellationTokenSource.

getToken

public CancellationToken getToken()
Returns:
the token that can be passed to asynchronous method to control cancellation.

cancel

public void cancel()
Cancels the token if it has not already been cancelled.

cancelAfter

public void cancelAfter(long delay)
Schedules a cancel operation on this CancellationTokenSource after the specified number of milliseconds.
Parameters:
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.

close

public void close()
Specified by:
close in interface java.io.Closeable
Specified by:
close in interface java.lang.AutoCloseable

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object