Sha256: dc4dd56b44fefc5a71c96afbb7c02a030ba43a90e642f02438131207de9c339d

Contents?: true

Size: 394 Bytes

Versions: 12

Compression:

Stored size: 394 Bytes

Contents

module Unipept
  class BatchOrder
    attr_reader :order

    def initialize
      @order = {}
      @current = 0
    end

    # Executes block if it's its turn, queues the block in the other case.
    def wait(i, &block)
      @order[i] = block
      return unless i == @current
      while order[@current]
        order.delete(@current).call
        @current += 1
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
unipept-1.4.0 lib/batch_order.rb
unipept-1.3.0 lib/batch_order.rb
unipept-1.2.0 lib/batch_order.rb
unipept-1.1.3 lib/batch_order.rb
unipept-1.1.2 lib/batch_order.rb
unipept-1.1.1 lib/batch_order.rb
unipept-1.1.0 lib/batch_order.rb
unipept-1.0.1 lib/batch_order.rb
unipept-1.0.0 lib/batch_order.rb
unipept-0.10.0 lib/batch_order.rb
unipept-0.9.0 lib/batch_order.rb
unipept-0.8.0 lib/batch_order.rb