Sha256: 788ca72e5ee5ce669073996c968896de667d19f336d924b7390ba7f53ea2986b

Contents?: true

Size: 602 Bytes

Versions: 8

Compression:

Stored size: 602 Bytes

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony'

resource_count = 0
Pool = Polyphony::ResourcePool.new(limit: 3) do
  +"resource#{resource_count += 1}"
end

def user(number)
  loop do
    Polyphony::CancelScope.new(timeout: 0.2) do |scope|
      scope.on_cancel { puts "#{number} (cancelled)" }
      Pool.acquire do |r|
        puts "#{number} #{r.inspect} >"
        sleep(0.1 + rand * 0.2)
        puts "#{number} #{r.inspect} <"
      end
    end
  end
end

10.times do |x|
  spin { user(x + 1) }
end

t0 = Time.now
throttled_loop(0.1) { puts "uptime: #{Time.now - t0}" }

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
polyphony-0.31 examples/core/xx-resource_cancel.rb
polyphony-0.30 examples/core/xx-resource_cancel.rb
polyphony-0.29 examples/core/xx-resource_cancel.rb
polyphony-0.28 examples/core/xx-resource_cancel.rb
polyphony-0.27 examples/core/xx-resource_cancel.rb
polyphony-0.26 examples/core/xx-resource_cancel.rb
polyphony-0.25 examples/core/xx-resource_cancel.rb
polyphony-0.24 examples/core/xx-resource_cancel.rb