Sha256: e6542977d6d61a41849ed0da88814a4a7aca67ba4910bf5b09353c83c2769a7e

Contents?: true

Size: 1.66 KB

Versions: 14

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony'

Exception.__disable_sanitized_backtrace__ = true

class Test
  def test_sleep
    puts "going to sleep"
    sleep 1
    puts "done sleeping"
  end
  
  def test_spin
    spin {
      10.times {
        STDOUT << '.'
        sleep 0.1
      }
    }
    
    puts "going to sleep\n"
    sleep 1
    puts 'woke up'
  end
  
  def test_file
    f = File.open(__FILE__, 'r')
    puts Thread.current.agent.read(f, +'', 10000, true)
    
    Thread.current.agent.write(STDOUT, "Write something: ")
    str = +''
    Thread.current.agent.read(STDIN, str, 5, false)
    puts str
  end
  
  def test_fork
    pid = fork do
      Thread.current.agent.post_fork
      puts 'child going to sleep'
      sleep 1
      puts 'child done sleeping'
      exit(42)
    end
    
    puts "Waiting for pid #{pid}"
    result = Thread.current.agent.waitpid(pid)
    puts "Done waiting"
    p result
  end
  
  def test_async
    async = Polyphony::Event.new
    
    spin {
      puts "signaller starting"
      sleep 1
      puts "signal"
      async.signal(:foo)
    }
    
    puts "awaiting event"
    p async.await
  end
  
  def test_queue
    q = Gyro::Queue.new
    spin {
      10.times {
        q << Time.now.to_f
        sleep 0.2
      }
      q << :STOP
    }
    
    loop do
      value = q.shift
      break if value == :STOP
      
      p value
    end
  end
  
  def test_thread
    t = Thread.new do
      puts "thread going to sleep"
      sleep 0.2
      puts "thread done sleeping"
    end
    
    t.await
  end
end

t = Test.new

t.methods.select { |m| m =~ /^test_/ }.each do |m|
  puts '*' * 40
  puts m
  t.send(m)
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
polyphony-0.44.0 examples/core/xx-agent.rb
polyphony-0.43.11 examples/core/xx-agent.rb
polyphony-0.43.10 examples/core/xx-agent.rb
polyphony-0.43.9 examples/core/xx-agent.rb
polyphony-0.43.8 examples/core/xx-agent.rb
polyphony-0.43.6 examples/core/xx-agent.rb
polyphony-0.43.5 examples/core/xx-agent.rb
polyphony-0.43.4 examples/core/xx-agent.rb
polyphony-0.43.3 examples/core/xx-agent.rb
polyphony-0.43.2 examples/core/xx-agent.rb
polyphony-0.43.1 examples/core/xx-agent.rb
polyphony-0.43 examples/core/xx-agent.rb
polyphony-0.42 examples/core/xx-agent.rb
polyphony-0.41 examples/core/xx-agent.rb