CancellationToken Class

定义

A CancellationToken is used to propagate notification that operations should be canceled. You create a cancellation token by instantiating a system.fabric.CancellationTokenSource object, which manages cancellation tokens retrieved from its system.fabric.CancellationTokenSource#getToken() method. You then pass the cancellation token to any number of operations that should receive notice of cancellation. The token cannot be used to initiate cancellation. When the owning object calls system.fabric.CancellationTokenSource#cancel(), the cancelled property on the cancellation token is set to true. The objects that receive the notification can respond in whatever manner is appropriate.

public class CancellationToken
继承
java.lang.Object
AutoCloseable
CancellationToken

方法

canBeCancelled()

Specifies if the Cancellation token can be cancelled or not. If the system.fabric.CancellationToken is created using system.fabric.CancellationTokenSource#getToken(), then the token can cancelled using system.fabric.CancellationTokenSource#cancel() method. If the system.fabric.CancellationToken is created using system.fabric.CancellationToken#getDefault(), then it can not be cancelled. It simply acts as a dummy token.

close()
getDefault()

Creates and returns a Cancellation token object. This method should be used when the CancellationToken doesn't support cancellation. Only Cancellation tokens created through CancellationTokenSource#getToken() supports cancellations.

isCancelled()

Gets whether cancellation has been requested for this token.

registerCancellationCallback(Runnable callback)

Registers a callback which will be executed when this system.fabric.CancellationToken object is cancelled.

registerCancellationCallback(String name, Runnable callback)

Registers a callback which will be executed when this system.fabric.CancellationToken object is cancelled.

throwIfCancellationRequested()

Throws a CancellationException if this token has had cancellation requested.

unregisterCancellationCallback()

unregister the callback for this system.fabric.CancellationToken object.

unregisterCancellationCallback(String name)

unregister the callback for this system.fabric.CancellationToken object.

适用于