Class: Async::LimitedQueue
- Inherits:
-
Queue
- Object
- Condition
- Notification
- Queue
- Async::LimitedQueue
- Defined in:
- lib/async/queue.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
Attributes inherited from Queue
Instance Method Summary collapse
- #dequeue ⇒ Object
- #enqueue(item) ⇒ Object
-
#initialize(limit = 1, **options) ⇒ LimitedQueue
constructor
A new instance of LimitedQueue.
-
#limited? ⇒ Boolean
Whether trying to enqueue an item would block.
Methods inherited from Queue
Methods inherited from Notification
Methods inherited from Condition
Constructor Details
#initialize(limit = 1, **options) ⇒ LimitedQueue
Returns a new instance of LimitedQueue.
67 68 69 70 71 72 73 |
# File 'lib/async/queue.rb', line 67 def initialize(limit = 1, **) super(**) @limit = limit @full = Notification.new end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
75 76 77 |
# File 'lib/async/queue.rb', line 75 def limit @limit end |
Instance Method Details
#dequeue ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/async/queue.rb', line 90 def dequeue item = super @full.signal return item end |
#enqueue(item) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/async/queue.rb', line 82 def enqueue item while limited? @full.wait end super end |
#limited? ⇒ Boolean
Returns Whether trying to enqueue an item would block.
78 79 80 |
# File 'lib/async/queue.rb', line 78 def limited? @items.size >= @limit end |