Class GAsyncWorkQueue<T>

java.lang.Object
com.glitchybyte.glib.concurrent.workqueue.GAsyncWorkQueue<T>
Type Parameters:
T - Type of work item.

public final class GAsyncWorkQueue<T> extends Object
A queue of work with the following characteristics:
  • Able to queue work items from multiple threads with minimal lock contention.
  • Work is serviced separately from the queue, allowing work to be performed without blocking the queue.
  • Constructor Details

    • GAsyncWorkQueue

      public GAsyncWorkQueue()
      Creates an asynchronous work queue.
  • Method Details

    • addWork

      public void addWork(T item)
      Adds a work item to the queue.
      Parameters:
      item - Work item.
    • awaitWork

      public void awaitWork() throws InterruptedException
      Awaits for work to be queued.

      awaitWork and doWork must be called on the same thread.

      Throws:
      InterruptedException - If the thread is interrupted while awaiting.
    • doWork

      public void doWork(Consumer<T> itemConsumer)
      Performs work on every item queued.

      awaitWork and doWork must be called on the same thread.

      Parameters:
      itemConsumer - Consumer that performs work on items.