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