Class CancellationTokens


  • public class CancellationTokens
    extends Object
    • Field Detail

      • None

        public static final CancellationToken None
        A cancellation token that will never be cancelled.
    • Constructor Detail

      • CancellationTokens

        public CancellationTokens()
    • 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.