Class: Thespian::Strategy::Fiber
- Inherits:
-
Object
- Object
- Thespian::Strategy::Fiber
- Includes:
- Interface
- Defined in:
- lib/thespian/strategies/fiber.rb
Overview
:nodoc:
Instance Method Summary collapse
- #<<(message) ⇒ Object
-
#initialize(&block) ⇒ Fiber
constructor
A new instance of Fiber.
- #mailbox_size ⇒ Object
- #messages ⇒ Object
- #receive ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Methods included from Interface
Constructor Details
#initialize(&block) ⇒ Fiber
Returns a new instance of Fiber.
15 16 17 18 19 |
# File 'lib/thespian/strategies/fiber.rb', line 15 def initialize(&block) @block = block @mailbox = [] @mailbox_cond = Strand::ConditionVariable.new end |
Instance Method Details
#<<(message) ⇒ Object
31 32 33 34 35 |
# File 'lib/thespian/strategies/fiber.rb', line 31 def <<() @mailbox << @mailbox_cond.signal self end |
#mailbox_size ⇒ Object
37 38 39 |
# File 'lib/thespian/strategies/fiber.rb', line 37 def mailbox_size @mailbox.size end |
#messages ⇒ Object
41 42 43 |
# File 'lib/thespian/strategies/fiber.rb', line 41 def @mailbox.dup end |
#receive ⇒ Object
26 27 28 29 |
# File 'lib/thespian/strategies/fiber.rb', line 26 def receive @mailbox_cond.wait while @mailbox.empty? @mailbox.shift end |
#start ⇒ Object
21 22 23 24 |
# File 'lib/thespian/strategies/fiber.rb', line 21 def start @strand = Strand.new{ @block.call } self end |
#stop ⇒ Object
45 46 47 48 |
# File 'lib/thespian/strategies/fiber.rb', line 45 def stop self << Stop.new @strand.join end |