Package com.tapkey.mobile.concurrent
Interface CancellationToken
-
public interface CancellationToken
Objects that allow cancelling long running operations. They are most often used to control async program flows in conjunction withPromise
. Cancellation tokens can be produced usingCancellationTokenSource
.- See Also:
CancellationTokenSource
,Promise
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description String
getMessage()
Returns the cancellation message if any.boolean
isCancellationRequested()
Returns whether cancellation has been requested.CancellationTokenRegistration
register(Action<? extends RuntimeException> observer)
Registers a function that is invoked when cancellation is requested.CancellationTokenRegistration
register(Action<? extends RuntimeException> observer, boolean useScheduler)
Registers a function that is invoked when cancellation is requested.void
throwIfCancellationRequested()
Throws an exception in caseisCancellationRequested()
evaluates to true.
-
-
-
Method Detail
-
isCancellationRequested
boolean isCancellationRequested()
Returns whether cancellation has been requested.- Returns:
- true, if cancellation has already been requested, false if not.
-
getMessage
String getMessage()
Returns the cancellation message if any.- Returns:
- the cancellation message if any.
- Throws:
IllegalStateException
- if the token has not been cancelled.
-
throwIfCancellationRequested
void throwIfCancellationRequested()
Throws an exception in caseisCancellationRequested()
evaluates to true.
-
register
CancellationTokenRegistration register(Action<? extends RuntimeException> observer)
Registers a function that is invoked when cancellation is requested. The callback is invoked on the current AsyncScheduler. If a listener is added while already in a cancelled state, this listener is called immediately and synchronously.- Parameters:
observer
- the action to invoke when cancellation is requested.- Returns:
- an Observable that is invoked if cancellation is requested or immediately if already cancelled.
-
register
CancellationTokenRegistration register(Action<? extends RuntimeException> observer, boolean useScheduler)
Registers a function that is invoked when cancellation is requested. If a listener is added while already in a cancelled state, this listener is called immediately and synchronously.- Parameters:
observer
- the action to invoke when cancellation is requested.useScheduler
- if set to true, the current AsyncScheduler is captured and used for invoking the callback.- Returns:
- an Observable that is invoked if cancellation is requested or immediately if already cancelled.
-
-