Class AwaitUtils

java.lang.Object
io.servicetalk.concurrent.test.internal.AwaitUtils

public final class AwaitUtils extends Object
Utilities to do blocking await calls for tests.
  • Method Details

    • await

      public static void await(CountDownLatch latch)
      Await a CountDownLatch until the latch is counted down, throws unchecked InterruptedException.
      Parameters:
      latch - the CountDownLatch to await.
    • await

      public static boolean await(CountDownLatch latch, long timeout, TimeUnit unit)
      Await a CountDownLatch until the latch is counted down or the given time duration expires, throws unchecked InterruptedException.
      Parameters:
      latch - the CountDownLatch to await.
      timeout - the timeout duration to await for.
      unit - the units applied to timeout.
      Returns:
      true if the count reached zero and false if the waiting time elapsed before the count reached zero
    • take

      public static <T> T take(BlockingQueue<T> queue)
      BlockingQueue.take() from the queue or throws unchecked exception in the case of InterruptedException.
      Type Parameters:
      T - The types of objects in the queue.
      Parameters:
      queue - The queue to take from.
      Returns:
      see BlockingQueue.take().
    • poll

      @Nullable public static <T> T poll(BlockingQueue<T> queue, long timeout, TimeUnit unit)
      BlockingQueue.poll(long, TimeUnit) from the queue, throws unchecked Exception if thread is interrupted while waiting.
      Type Parameters:
      T - The types of objects in the queue.
      Parameters:
      queue - the queue to poll from.
      timeout - the timeout duration to poll for.
      unit - the units applied to timeout.
      Returns:
      see BlockingQueue.poll(long, TimeUnit).