Module: Minx
- Defined in:
- lib/minx.rb,
lib/minx/channel.rb,
lib/minx/process.rb
Defined Under Namespace
Class Method Summary collapse
-
.channel ⇒ Channel
Create a new channel.
-
.join(*processes) ⇒ nil
Wait for the processes to yield execution.
-
.select(*choices) ⇒ Object
Select from a list of channels.
-
.spawn(&block) ⇒ Process
Spawn a new process.
-
.yield(*args) ⇒ Object
Yield control to another process.
Class Method Details
.channel ⇒ Channel
Create a new channel.
20 21 22 |
# File 'lib/minx.rb', line 20 def self.channel Channel.new end |
.join(*processes) ⇒ nil
Wait for the processes to yield execution.
34 35 36 37 38 39 40 |
# File 'lib/minx.rb', line 34 def self.join(*processes) processes.each do |process| process.resume end return nil end |
.select(*choices) ⇒ Object
Select from a list of channels.
The channels will be enumerated in order; the first one carrying a message will be picked, and the message will be returned.
If none of the channels are readable, the calling process will yield until a channel is written to, unless :skip => true is passed as an option, in which case the call will just return nil.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/minx.rb', line 56 def self.select(*choices) = choices.last.is_a?(Hash) ? choices.pop : {} # If a choice is readable, just receive from that one. choices.each do |choice| return choice.receive if choice.readable? end # Return immediately if :skip => true return if [:skip] # ... otherwise, wait for a channel to become readable. choices.each do |choice| choice.receive(:async => true) end Minx.yield end |
.spawn(&block) ⇒ Process
Spawn a new process.
13 14 15 |
# File 'lib/minx.rb', line 13 def self.spawn(&block) Process.new(&block).spawn end |
.yield(*args) ⇒ Object
Yield control to another process.
The calling process will be resumed at a later point.
27 28 29 |
# File 'lib/minx.rb', line 27 def self.yield(*args) Fiber.yield(*args) end |