Package com.tapkey.mobile.concurrent
Class CancellationTokens
- java.lang.Object
-
- com.tapkey.mobile.concurrent.CancellationTokens
-
public class CancellationTokens extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static CancellationToken
None
A cancellation token that will never be cancelled.
-
Constructor Summary
Constructors Constructor Description CancellationTokens()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CancellationToken
any(CancellationToken... tokens)
Creates a cancellation token that goes into cancelled state if at least one of the specified tokens goes into cancelled state.static CancellationToken
fromTimeout(int timeoutMs)
Creates a cancellation token that goes into cancelled state after the specified timeout period elapsed.static CancellationToken
withTimeout(CancellationToken original, int timeoutMs)
Creates a cancellation token that goes into cancelled state when either the specified timeout period elapsed or the specified token goes into cancelled state, whatever happens first.
-
-
-
Field Detail
-
None
public static final CancellationToken None
A cancellation token that will never be cancelled.
-
-
Method Detail
-
any
public static CancellationToken any(CancellationToken... tokens)
Creates a cancellation token that goes into cancelled state if at least one of the specified tokens goes into cancelled state.- Parameters:
tokens
- the source cancellation tokens.- Returns:
- a cancellation token that goes into cancelled state if at least one of the specified tokens goes into cancelled state.
-
withTimeout
public static CancellationToken withTimeout(CancellationToken original, int timeoutMs)
Creates a cancellation token that goes into cancelled state when either the specified timeout period elapsed or the specified token goes into cancelled state, whatever happens first.- Parameters:
original
- the original token to observ.timeoutMs
- the timeout period in milliseconds.- Returns:
- a cancellation token that goes into cancelled state when either the specified timeout period elapsed or the specified token goes into cancelled state, whatever happens first.
-
fromTimeout
public static CancellationToken fromTimeout(int timeoutMs)
Creates a cancellation token that goes into cancelled state after the specified timeout period elapsed.- Parameters:
timeoutMs
- the timeout period in milliseconds.- Returns:
- a cancellation token that goes into cancelled state after the specified timeout period elapsed.
-
-