Class: Readme::RequestQueue
- Inherits:
-
Object
- Object
- Readme::RequestQueue
- Defined in:
- lib/readme/request_queue.rb
Instance Method Summary collapse
-
#initialize(api_key, buffer_length) ⇒ RequestQueue
constructor
A new instance of RequestQueue.
- #length ⇒ Object
- #push(request) ⇒ Object
Constructor Details
#initialize(api_key, buffer_length) ⇒ RequestQueue
Returns a new instance of RequestQueue.
5 6 7 8 9 10 |
# File 'lib/readme/request_queue.rb', line 5 def initialize(api_key, buffer_length) @queue = [] @buffer_length = buffer_length @api_key = api_key @lock = Mutex.new end |
Instance Method Details
#length ⇒ Object
23 24 25 |
# File 'lib/readme/request_queue.rb', line 23 def length @queue.length end |
#push(request) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/readme/request_queue.rb', line 12 def push(request) @lock.synchronize do @queue << request if ready_to_send? payloads = @queue.slice!(0, @buffer_length) send_payloads(payloads) end end end |