透明思考


Transparent Thoughts


Is Concurrent Ruby Better?

Code withThe Omnibus Concurrency Library

require ‘concurrent/actors’include Concurrent::ActorsMessage = Struct.new :ping, :pongping_thread = Actor.spawn doloop doActor.receive do |f|f.when Message do |m|puts “PING”sleep(1)m.pong  Message.new(m.ping, m.pong)endendendendpong_thread = Actor.spawn doloop doActor.receive do |f|f.when Message do |m|puts “PONG”sleep(1)m.ping  Message.new(m.ping, m.pong)endendendendping_thread  Message.new(ping_thread, pong_thread)while(true)puts(“WAITING…”)sleep(5)end

Also, it runs…forever.