Sha256: df2c7d46ad7bdabd2ebae2143348faf75ea004d79c15a730e15b6dc1c750b0bb

Contents?: true

Size: 696 Bytes

Versions: 26

Compression:

Stored size: 696 Bytes

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony'

def echo(cin, cout)
  puts 'start echoer'
  while (msg = cin.receive)
    cout << "you said: #{msg}"
  end
ensure
  puts 'echoer stopped'
end

chan1, chan2 = 2.times.map { Polyphony::Channel.new }

spin { echo(chan1, chan2) }

spin do
  puts 'start receiver'
  while (msg = chan2.receive)
    puts msg
    $main.resume if msg =~ /world/
  end
ensure
  puts 'receiver stopped'
end

$main = spin do
  puts 'start main'
  t0 = Time.now
  puts 'send hello'
  chan1 << 'hello'
  puts 'send world'
  chan1 << 'world'

  suspend

  puts 'closing channels'
  chan1.close
  chan2.close
  puts "done #{Time.now - t0}"
end

suspend

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
polyphony-0.43.8 examples/core/xx-channels.rb
polyphony-0.43.6 examples/core/xx-channels.rb
polyphony-0.43.5 examples/core/xx-channels.rb
polyphony-0.43.4 examples/core/xx-channels.rb
polyphony-0.43.3 examples/core/xx-channels.rb
polyphony-0.43.2 examples/core/xx-channels.rb
polyphony-0.43.1 examples/core/xx-channels.rb
polyphony-0.43 examples/core/xx-channels.rb
polyphony-0.42 examples/core/xx-channels.rb
polyphony-0.41 examples/core/xx-channels.rb
polyphony-0.40 examples/core/xx-channels.rb
polyphony-0.39 examples/core/xx-channels.rb
polyphony-0.38 examples/core/xx-channels.rb
polyphony-0.36 examples/core/xx-channels.rb
polyphony-0.34 examples/core/xx-channels.rb
polyphony-0.33 examples/core/xx-channels.rb
polyphony-0.32 examples/core/xx-channels.rb
polyphony-0.31 examples/core/xx-channels.rb
polyphony-0.30 examples/core/xx-channels.rb
polyphony-0.29 examples/core/xx-channels.rb