Sha256: 7dec918517ea2347c5df1fa66a8d6d9b59e033f63a3ac3cbb61f81245249a2b1

Contents?: true

Size: 636 Bytes

Versions: 4

Compression:

Stored size: 636 Bytes

Contents

module ProconBypassMan
  class ServerPool
    def initialize(servers: )
      if servers.nil? || servers.empty?
        return
      end

      @servers = servers
      if @servers.size >= 1
        @index = 0
      else
        @index = nil
      end
    end

    def pick
      if @index.nil?
        return @servers&.first
      end
      @servers[@index] or raise "bug!!!"
    end
    def server; pick; end

    def next!
      inc_index
      if @servers[@index].nil?
        reset
        return
      end
    end

    private

    def reset
      @index = 0
    end

    def inc_index
      @index = @index + 1
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
procon_bypass_man-0.1.16.1 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.1.16 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.1.15 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.1.14 lib/procon_bypass_man/support/server_pool.rb