Class: Ratomic::Queue
- Inherits:
-
Object
- Object
- Ratomic::Queue
- Defined in:
- lib/ratomic/queue.rb
Overview
A Ractor-shareable multi-producer, multi-consumer queue.
Queue stores Ruby objects in a fixed-size native ring buffer. Push blocks when the queue is full; pop blocks when the queue is empty.
Class Method Summary collapse
-
.new(capacity) ⇒ Ratomic::Queue
Create a queue with a fixed capacity.
Instance Method Summary collapse
-
#<<(item) ⇒ Ratomic::Queue
Push an item and return the queue for chaining.
-
#empty? ⇒ Boolean
Check whether the queue currently appears empty.
-
#length ⇒ Integer
Alias for #size.
-
#peek ⇒ Object?
Return the next item without removing it.
-
#pop ⇒ Object
Pop an item, blocking until one is available.
-
#push(item) ⇒ void
Push an item, blocking until space is available.
-
#size ⇒ Integer
Return the current queue size.
Class Method Details
.new(capacity) ⇒ Ratomic::Queue
Create a queue with a fixed capacity.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ratomic/queue.rb', line 61 class Queue # Push an item and return the queue for chaining. # # @param item [Object] # @return [Ratomic::Queue] def <<(item) push(item) self end end |
Instance Method Details
#<<(item) ⇒ Ratomic::Queue
Push an item and return the queue for chaining.
66 67 68 69 |
# File 'lib/ratomic/queue.rb', line 66 def <<(item) push(item) self end |
#empty? ⇒ Boolean
Check whether the queue currently appears empty.
Since this is a concurrent queue, the value is a moment-in-time observation.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ratomic/queue.rb', line 61 class Queue # Push an item and return the queue for chaining. # # @param item [Object] # @return [Ratomic::Queue] def <<(item) push(item) self end end |
#length ⇒ Integer
Alias for #size.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ratomic/queue.rb', line 61 class Queue # Push an item and return the queue for chaining. # # @param item [Object] # @return [Ratomic::Queue] def <<(item) push(item) self end end |
#peek ⇒ Object?
Return the next item without removing it.
Since this is a concurrent queue, the value is a moment-in-time observation.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ratomic/queue.rb', line 61 class Queue # Push an item and return the queue for chaining. # # @param item [Object] # @return [Ratomic::Queue] def <<(item) push(item) self end end |
#pop ⇒ Object
Pop an item, blocking until one is available.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ratomic/queue.rb', line 61 class Queue # Push an item and return the queue for chaining. # # @param item [Object] # @return [Ratomic::Queue] def <<(item) push(item) self end end |
#push(item) ⇒ void
This method returns an undefined value.
Push an item, blocking until space is available.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ratomic/queue.rb', line 61 class Queue # Push an item and return the queue for chaining. # # @param item [Object] # @return [Ratomic::Queue] def <<(item) push(item) self end end |
#size ⇒ Integer
Return the current queue size.
Since this is a concurrent queue, the value is a moment-in-time observation.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ratomic/queue.rb', line 61 class Queue # Push an item and return the queue for chaining. # # @param item [Object] # @return [Ratomic::Queue] def <<(item) push(item) self end end |