class Buffer
Represents a job buffer that stores and manages job execution. The buffer acts as an intermediary between job producers and consumers, providing a thread-safe queue for job storage and optional delegation.
Definitions
def initialize(delegate = nil)
Initialize a new job buffer.
Signature
-
parameter
delegate
Object | nil
An optional delegate object that will receive job events.
Implementation
def initialize(delegate = nil)
@jobs = Async::Queue.new
@delegate = delegate
end
def empty?
Check if the buffer contains any pending jobs.
Signature
-
returns
Boolean
True if the buffer is empty, false otherwise.
Implementation
def empty?
@jobs.empty?
end
attr :jobs
Signature
-
attribute
Async::Queue
The internal queue containing pending jobs.
def call(job)
Add a job to the buffer and optionally delegate to the configured delegate.
Signature
-
parameter
job
Object
The job to be added to the buffer.
Implementation
def call(job)
@jobs.enqueue(job)
@delegate&.call(job)
end
def pop
Remove and return the next job from the buffer.
Signature
-
returns
Object | nil
The next job from the buffer, or nil if empty.
Implementation
def pop
@jobs.dequeue
end
def start
Start the buffer's delegate if one is configured.
Implementation
def start
@delegate&.start
end
def stop
Stop the buffer's delegate if one is configured.
Implementation
def stop
@delegate&.stop
end