class Thread::Process
A process should only interact with the outside through messages, it still uses a thread, but it should make it safer to use than sharing and locks.
Public Class Methods
[](name)
click to toggle source
# File lib/thread/process.rb, line 28 def self.[](name) all[name] end
all()
click to toggle source
# File lib/thread/process.rb, line 16 def self.all @@processes ||= {} end
new(&block)
click to toggle source
Create a new process executing the block.
# File lib/thread/process.rb, line 33 def initialize(&block) @channel = Thread::Channel.new Thread.new { instance_eval(&block) @channel = nil } end
register(name, process)
click to toggle source
# File lib/thread/process.rb, line 20 def self.register(name, process) all[name] = process end
unregister(name)
click to toggle source
# File lib/thread/process.rb, line 24 def self.unregister(name) all.delete(name) end
Public Instance Methods
send(what)
click to toggle source
Send a message to the process.
# File lib/thread/process.rb, line 44 def send(what) unless @channel raise RuntimeError, 'the process has terminated' end @channel.send(what) self end
Also aliased as: <<
Private Instance Methods
receive()
click to toggle source
# File lib/thread/process.rb, line 57 def receive @channel.receive end
receive!()
click to toggle source
# File lib/thread/process.rb, line 61 def receive! @channel.receive! end