Package com.azure.android.core.util
Class CancellationToken
- java.lang.Object
-
- com.azure.android.core.util.CancellationToken
-
public final class CancellationToken extends java.lang.Object
Type representing a token to cancel one or more operations.
-
-
Field Summary
Fields Modifier and Type Field Description static CancellationToken
NONE
An empty CancellationToken that cannot be cancelled.
-
Constructor Summary
Constructors Constructor Description CancellationToken()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
Communicates a request for cancellation.boolean
isCancellationRequested()
Gets whether cancellation has been requested for this token by callingcancel()
.void
registerOnCancel(java.lang.Runnable onCancel)
Registers aRunnable
that will be called when this CancellationToken is canceled.void
registerOnCancel(java.lang.String id, java.lang.Runnable onCancel)
Registers aRunnable
that will be called when this CancellationToken is canceled.void
unregisterOnCancel(java.lang.String id)
Unregister theRunnable
that was registered usingregisterOnCancel(String, Runnable)
.
-
-
-
Field Detail
-
NONE
public static final CancellationToken NONE
An empty CancellationToken that cannot be cancelled.
-
-
Method Detail
-
cancel
public void cancel()
Communicates a request for cancellation.
-
isCancellationRequested
public boolean isCancellationRequested()
Gets whether cancellation has been requested for this token by callingcancel()
.- Returns:
true
if cancellation has been requested, otherwise.
-
registerOnCancel
public void registerOnCancel(java.lang.Runnable onCancel)
Registers aRunnable
that will be called when this CancellationToken is canceled. This operation of registering theRunnable
is non-blocking and thread-safe. If the token is already in the cancelled state then the provided Runnable will be immediately executed. This is O(1) in best case and O(k) in worst, where k is number of concurrent threads in case of race.- Parameters:
onCancel
- TheRunnable
to be executed when the CancellationToken is canceled.
-
registerOnCancel
public void registerOnCancel(java.lang.String id, java.lang.Runnable onCancel)
Registers aRunnable
that will be called when this CancellationToken is canceled. This operation of registering theRunnable
is non-blocking and thread-safe. If the token is already in the cancelled state then the provided Runnable will be immediately executed. This is O(1) in best case and O(k) in worst, where k is number of concurrent threads in case of race in registering Callback.- Parameters:
id
- The registration id for theRunnable
to register.onCancel
- TheRunnable
to be executed when the CancellationToken is canceled.
-
unregisterOnCancel
public void unregisterOnCancel(java.lang.String id)
Unregister theRunnable
that was registered usingregisterOnCancel(String, Runnable)
. This unregister operation is non-blocking and thread-safe.- Parameters:
id
- The id of theRunnable
to unregister.
-
-