Sha256: a4c7db0107c28efe833028925d720ca1160cb8bc84f239abdc9d97f9ab84665b

Contents?: true

Size: 707 Bytes

Versions: 25

Compression:

Stored size: 707 Bytes

Contents

# frozen_string_literal: true
module Dynflow
  # A simple round-robin scheduling implementation used at various
  # places in Dynflow
  class RoundRobin
    def initialize
      @data   = []
      @cursor = 0
    end

    def add(item)
      @data.push item
      self
    end

    def delete(item)
      @data.delete item
      self
    end

    def next
      @cursor = 0 if @cursor > @data.size-1
      @data[@cursor]
    ensure
      @cursor += 1
    end

    def empty?
      @data.empty?
    end

    # the `add` and `delete` methods should be preferred, but
    # sometimes the list of things to iterate though can not be owned
    # by the round robin object itself
    attr_writer :data
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
dynflow-1.8.2 lib/dynflow/round_robin.rb
dynflow-1.8.1 lib/dynflow/round_robin.rb
dynflow-1.8.0 lib/dynflow/round_robin.rb
dynflow-1.7.0 lib/dynflow/round_robin.rb
dynflow-1.6.11 lib/dynflow/round_robin.rb
dynflow-1.6.10 lib/dynflow/round_robin.rb
dynflow-1.6.8 lib/dynflow/round_robin.rb
dynflow-1.6.7 lib/dynflow/round_robin.rb
dynflow-1.6.6 lib/dynflow/round_robin.rb
dynflow-1.6.5 lib/dynflow/round_robin.rb
dynflow-1.6.4 lib/dynflow/round_robin.rb
dynflow-1.6.3 lib/dynflow/round_robin.rb
dynflow-1.6.2 lib/dynflow/round_robin.rb
dynflow-1.6.1 lib/dynflow/round_robin.rb
dynflow-1.4.9 lib/dynflow/round_robin.rb
dynflow-1.4.8 lib/dynflow/round_robin.rb
dynflow-1.5.0 lib/dynflow/round_robin.rb
dynflow-1.4.7 lib/dynflow/round_robin.rb
dynflow-1.4.6 lib/dynflow/round_robin.rb
dynflow-1.4.5 lib/dynflow/round_robin.rb