Class: EventMachine::ThrottledQueue
- Inherits:
-
Queue
- Object
- Queue
- EventMachine::ThrottledQueue
- Defined in:
- lib/em/throttled_queue.rb,
lib/em/throttled_queue/version.rb
Overview
TODO:
Add a maximum size-limit on amount of items in queue.
An EM::Queue with a rate-limit applied to it. This is useful if you wish to consume items at a limited pace.
Constant Summary collapse
- VERSION =
Gem version, following Semantic Versioning since v1.0.2
[1, 1, 1].join('.')
Instance Method Summary collapse
-
#initialize(limit, refresh_interval = 1) ⇒ ThrottledQueue
constructor
Create a new rate-limited queue.
-
#pop {|item| ... } ⇒ ThrottledQueue
Pop an item off the queue as soon as conditions allow, passing it to the given block.
-
#push(*items) ⇒ ThrottledQueue
Push items onto the queue (from within the reactor thread) asap.
Constructor Details
#initialize(limit, refresh_interval = 1) ⇒ ThrottledQueue
Create a new rate-limited queue.
24 25 26 27 28 29 30 31 32 |
# File 'lib/em/throttled_queue.rb', line 24 def initialize(limit, refresh_interval = 1) @credits = @limit = limit.to_i @ticker = EM::add_periodic_timer(refresh_interval) do @credits = @limit scheduled_dequeue end super() end |
Instance Method Details
#pop {|item| ... } ⇒ ThrottledQueue
Note:
The given block is executed within the reactor thread.
Pop an item off the queue as soon as conditions allow, passing it to the given block.
42 43 44 |
# File 'lib/em/throttled_queue.rb', line 42 def pop(&block) interact { @popq.push(block) } end |
#push(*items) ⇒ ThrottledQueue
Note:
This call is thread-safe.
Push items onto the queue (from within the reactor thread) asap.
51 52 53 |
# File 'lib/em/throttled_queue.rb', line 51 def push(*items) interact { @items.push(*items) } end |