class Async::Queue
@public Since ‘stable-v1`.
It has a compatible interface with {Notification} and {Condition}, except that it’s multi-value.
A queue which allows items to be processed in order.
def <<(item)
def <<(item) @items << item @available.signal unless self.empty? end
def async(parent: (@parent or Task.current), **options, &block)
@parameter options [Hash] The options to pass to the task.
@parameter parent [Interface(:async) | Nil] The parent task to use for async operations.
@parameter arguments [Array] The arguments to pass to the block.
@asynchronous Executes the given block concurrently for each item.
Process each item in the queue.
def async(parent: (@parent or Task.current), **options, &block) while item = self.dequeue parent.async(item, **options, &block) end end
def dequeue
def dequeue while @items.empty? @available.wait end @items.shift end
def each
def each while item = self.dequeue yield item end end
def empty?
def empty? @items.empty? end
def enqueue(*items)
def enqueue(*items) @items.concat(items) @available.signal unless self.empty? end
def initialize(parent: nil, available: Notification.new)
@parameter parent [Interface(:async) | Nil] The parent task to use for async operations.
Create a new queue.
def initialize(parent: nil, available: Notification.new) @items = [] @parent = parent @available = available end
def signal(value)
def signal(value) self.enqueue(value) end
def size
def size @items.size end
def wait
def wait self.dequeue end