Package com.tapkey.mobile.concurrent
Class CancellationTokenSource
- java.lang.Object
-
- com.tapkey.mobile.concurrent.CancellationTokenSource
-
public class CancellationTokenSource extends Object
This class provides functionality to control the execution of promises. It acts as a source for cancellation tokens.The example below demonstrates how to retrieve a CancellationToken and use it to cancel a pending operation.
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); CancellationToken ct = cancellationTokenSource.getToken(); // Pass the token to an asynchronous operation that accepts a CancellationToken asyncOperation(..., ct).conclude(); // If required, cancellation can be requested as follows: cancellationTokenSource.requestCancellation();
- See Also:
CancellationToken
,Promise
-
-
Constructor Summary
Constructors Constructor Description CancellationTokenSource()
Creates a new cancellation token source.CancellationTokenSource(boolean cancellationRequested)
Creates a new cancellation token source with cancellation already requested.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CancellationToken
getToken()
Returns theCancellationToken
associated with this instance.void
requestCancellation()
Requests cancellation of the affected promises.void
requestCancellation(String message)
Requests cancellation of the affected promises and allows specifying a custom message.
-
-
-
Constructor Detail
-
CancellationTokenSource
public CancellationTokenSource()
Creates a new cancellation token source.
-
CancellationTokenSource
public CancellationTokenSource(boolean cancellationRequested)
Creates a new cancellation token source with cancellation already requested. This eliminates the need to callrequestCancellation()
after instantiation if cancellation is to be requested at instantiation time.- Parameters:
cancellationRequested
- true, if cancellation is to be requested and false, if not.
-
-
Method Detail
-
requestCancellation
public void requestCancellation()
Requests cancellation of the affected promises.
-
requestCancellation
public void requestCancellation(String message)
Requests cancellation of the affected promises and allows specifying a custom message.
-
getToken
public CancellationToken getToken()
Returns theCancellationToken
associated with this instance.- Returns:
- the
CancellationToken
associated with this instance.
-
-