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-0.96 examples/core/resource_delegate.rb
polyphony-0.95 examples/core/resource_delegate.rb
polyphony-0.94 examples/core/resource_delegate.rb
polyphony-0.93 examples/core/resource_delegate.rb
polyphony-0.92 examples/core/resource_delegate.rb
polyphony-0.91 examples/core/resource_delegate.rb
polyphony-0.90 examples/core/resource_delegate.rb
polyphony-0.89 examples/core/resource_delegate.rb
polyphony-0.87 examples/core/resource_delegate.rb
polyphony-0.86 examples/core/resource_delegate.rb
polyphony-0.85 examples/core/resource_delegate.rb
polyphony-0.84.1 examples/core/resource_delegate.rb
polyphony-0.84 examples/core/resource_delegate.rb
polyphony-0.83 examples/core/resource_delegate.rb
polyphony-0.82 examples/core/resource_delegate.rb
polyphony-0.81.1 examples/core/resource_delegate.rb
polyphony-0.81 examples/core/resource_delegate.rb
polyphony-0.80 examples/core/resource_delegate.rb
polyphony-0.79 examples/core/resource_delegate.rb
polyphony-0.78 examples/core/resource_delegate.rb