Class: Thread::Process
- Inherits:
-
Object
- Object
- Thread::Process
- Defined in:
- lib/thread/process.rb
Overview
A process should only interact with the outside the outside through messages, it still uses a thread, but it should make it safer to use than sharing and locks.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(&block) ⇒ Process
constructor
Create a new process executing the block.
-
#send(what) ⇒ Object
(also: #<<)
Send a message to the process.
Constructor Details
Class Method Details
.[](name) ⇒ Object
29 30 31 |
# File 'lib/thread/process.rb', line 29 def self.[] (name) all[name] end |
.all ⇒ Object
17 18 19 |
# File 'lib/thread/process.rb', line 17 def self.all @@processes ||= {} end |
.register(name, process) ⇒ Object
21 22 23 |
# File 'lib/thread/process.rb', line 21 def self.register (name, process) all[name] = process end |
.unregister(name) ⇒ Object
25 26 27 |
# File 'lib/thread/process.rb', line 25 def self.unregister (name) all.delete(name) end |
Instance Method Details
#send(what) ⇒ Object Also known as: <<
Send a message to the process.
45 46 47 48 49 50 51 52 53 |
# File 'lib/thread/process.rb', line 45 def send (what) unless @channel raise RuntimeError, 'the process has terminated' end @channel.send(what) self end |