Class: Ractor::Pipeline::TokenPool
- Inherits:
-
Object
- Object
- Ractor::Pipeline::TokenPool
- Defined in:
- lib/ractor/pipeline.rb
Overview
Demand tokens of one pull group. Tokens are granted round-robin over the consumers (not in token arrival order): each consumer sends its CREDIT initial tokens in a burst, and handing them out in arrival order would cluster consecutive batches on the same worker.
Instance Method Summary collapse
- #add(port) ⇒ Object
-
#initialize ⇒ TokenPool
constructor
A new instance of TokenPool.
- #take ⇒ Object
Constructor Details
#initialize ⇒ TokenPool
Returns a new instance of TokenPool.
337 338 339 340 |
# File 'lib/ractor/pipeline.rb', line 337 def initialize @counts = Hash.new(0) @order = [] end |
Instance Method Details
#add(port) ⇒ Object
342 343 344 345 |
# File 'lib/ractor/pipeline.rb', line 342 def add(port) @order << port unless @counts.key?(port) @counts[port] += 1 end |
#take ⇒ Object
347 348 349 350 351 352 353 354 |
# File 'lib/ractor/pipeline.rb', line 347 def take @order.size.times do port = @order.shift @order.push(port) return port if @counts[port] > 0 && (@counts[port] -= 1 || true) end nil end |