Sha256: 0f7e3745ffa7d99cd088a8426bef726f9d39c4492dd3f8be265a9acbc9c08605

Contents?: true

Size: 453 Bytes

Versions: 90

Compression:

Stored size: 453 Bytes

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony'

class Number
  def initialize(id)
    @id = id
  end

  def greet(other)
    puts "You are number #{other}, I am number #{@id}"
    sleep rand(0.2..0.3)
  end
end

resource_count = 0
Pool = Polyphony::ResourcePool.new(limit: 3) do
  Number.new(resource_count += 1)
end

def meet(number)
  loop do
    Pool.greet(number)
  end
end

(4..10).each { |x| spin { meet(x) } }

sleep 1

Version data entries

90 entries across 90 versions & 1 rubygems

Version Path
polyphony-1.6 examples/core/resource_delegate.rb
polyphony-1.5 examples/core/resource_delegate.rb
polyphony-1.4 examples/core/resource_delegate.rb
polyphony-1.3 examples/core/resource_delegate.rb
polyphony-1.2.1 examples/core/resource_delegate.rb
polyphony-1.2 examples/core/resource_delegate.rb
polyphony-1.1.1 examples/core/resource_delegate.rb
polyphony-1.1 examples/core/resource_delegate.rb
polyphony-1.0.2 examples/core/resource_delegate.rb
polyphony-1.0.1 examples/core/resource_delegate.rb
polyphony-1.0 examples/core/resource_delegate.rb
polyphony-0.99.6 examples/core/resource_delegate.rb
polyphony-0.99.5 examples/core/resource_delegate.rb
polyphony-0.99.4 examples/core/resource_delegate.rb
polyphony-0.99.3 examples/core/resource_delegate.rb
polyphony-0.99.2 examples/core/resource_delegate.rb
polyphony-0.99.1 examples/core/resource_delegate.rb
polyphony-0.99 examples/core/resource_delegate.rb
polyphony-0.98 examples/core/resource_delegate.rb
polyphony-0.97 examples/core/resource_delegate.rb