Class: Unipept::BatchOrder
Instance Attribute Summary collapse
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
-
#initialize ⇒ BatchOrder
constructor
A new instance of BatchOrder.
-
#wait(i, &block) ⇒ Object
Executes block if it’s its turn, queues the block in the other case.
Constructor Details
#initialize ⇒ BatchOrder
Returns a new instance of BatchOrder.
5 6 7 8 |
# File 'lib/batch_order.rb', line 5 def initialize @order = {} @current = 0 end |
Instance Attribute Details
#order ⇒ Object (readonly)
Returns the value of attribute order.
3 4 5 |
# File 'lib/batch_order.rb', line 3 def order @order end |
Instance Method Details
#wait(i, &block) ⇒ Object
Executes block if it’s its turn, queues the block in the other case.
11 12 13 14 15 16 17 18 19 |
# File 'lib/batch_order.rb', line 11 def wait(i, &block) @order[i] = block return unless i == @current while order[@current] order.delete(@current).call @current += 1 end end |