Sha256: a912e4a726eeeb6b6c8973fb6dd7ce854921ce09a9b5033ca96a254ad98cff44

Contents?: true

Size: 769 Bytes

Versions: 95

Compression:

Stored size: 769 Bytes

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony'
require 'polyphony/core/channel'

def echo(cin, cout)
  puts 'start echoer'
  while (msg = cin.receive)
    puts "echoer received #{msg}"
    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.schedule 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

$main.await

Version data entries

95 entries across 95 versions & 1 rubygems

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