Android SDK Version
  • java.lang.Object
    • com.facebook.bolts.CancellationToken

public class CancellationToken
extends java.lang.Object
Propagates notification that operations should be canceled.
Create an instance of CancellationTokenSource and pass the token returned from CancellationTokenSource#getToken() to the asynchronous operation(s). Call CancellationTokenSource#cancel() to cancel the operations.
A CancellationToken can only be cancelled once - it should not be passed to future operations once cancelled.
Method Summary
Modifier and TypeMethod and Description
booleanisCancellationRequested() 
CancellationTokenRegistrationregister(java.lang.Runnable action)
Registers a runnable that will be called when this CancellationToken is canceled.
voidthrowIfCancellationRequested() 
java.lang.StringtoString() 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Method Detail

isCancellationRequested

public boolean isCancellationRequested()
Returns:
true if the cancellation was requested from the source, false otherwise.

register

public CancellationTokenRegistration register(java.lang.Runnable action)
Registers a runnable that will be called when this CancellationToken is canceled. If this token is already in the canceled state, the runnable will be run immediately and synchronously.
Parameters:
action - the runnable to be run when the token is cancelled.
Returns:
a CancellationTokenRegistration instance that can be used to unregister the action.

throwIfCancellationRequested

public void throwIfCancellationRequested()
                                  throws java.util.concurrent.CancellationException
Throws:
java.util.concurrent.CancellationException - if this token has had cancellation requested. May be used to stop execution of a thread or runnable.

toString

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