Package org.bsc.async

Class AsyncGeneratorQueue.Generator<E>

Type Parameters:
E - the type of elements in the queue
All Implemented Interfaces:
AutoCloseable, Iterable<E>, AsyncGenerator<E>, AsyncGenerator.Cancellable<E>, AsyncGenerator.IsCancellable
Enclosing interface:
AsyncGeneratorQueue

public static class AsyncGeneratorQueue.Generator<E> extends AsyncGenerator.BaseCancellable<E>
Inner class to generate asynchronous elements from the queue.
  • Constructor Details

    • Generator

      public Generator(BlockingQueue<AsyncGenerator.Data<E>> queue)
      Constructs a Generator with the specified queue.
      Parameters:
      queue - the blocking queue to generate elements from
  • Method Details

    • queue

    • next

      public AsyncGenerator.Data<E> next()
      Retrieves the next element from the queue asynchronously.
      Returns:
      the next element from the queue
    • cancel

      public boolean cancel(boolean mayInterruptIfRunning)
      Description copied from class: AsyncGenerator.BaseCancellable
      Requests cancellation of the generator.

      This method sets the cancelled flag and closes the executor to release resources. If mayInterruptIfRunning is true, the executor will be shut down immediately, interrupting any running tasks.

      Specified by:
      cancel in interface AsyncGenerator.IsCancellable
      Overrides:
      cancel in class AsyncGenerator.BaseCancellable<E>
      Parameters:
      mayInterruptIfRunning - if true, interrupt running tasks
      Returns:
      true if cancellation was successful, false if already cancelled