Class: Ruck::FiberShred
- Inherits:
-
Object
- Object
- Ruck::FiberShred
- Defined in:
- lib/ruck/shred.rb
Overview
See the documentation for CallccShred
Direct Known Subclasses
Constant Summary collapse
- @@current_shreds =
[]
Class Method Summary collapse
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #call(*args) ⇒ Object
- #finished? ⇒ Boolean
-
#initialize(&block) ⇒ FiberShred
constructor
A new instance of FiberShred.
- #kill ⇒ Object
- #pause ⇒ Object
- #running? ⇒ Boolean
Constructor Details
#initialize(&block) ⇒ FiberShred
Returns a new instance of FiberShred.
86 87 88 |
# File 'lib/ruck/shred.rb', line 86 def initialize(&block) @fiber = Fiber.new(&block) end |
Class Method Details
.current ⇒ Object
82 83 84 |
# File 'lib/ruck/shred.rb', line 82 def self.current @@current_shreds.last end |
Instance Method Details
#[](*args) ⇒ Object
108 109 110 |
# File 'lib/ruck/shred.rb', line 108 def [](*args) call(*args) end |
#call(*args) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/ruck/shred.rb', line 98 def call(*args) return unless @fiber @@current_shreds << self @fiber.resume rescue FiberError @fiber = nil ensure @@current_shreds.pop end |
#finished? ⇒ Boolean
112 113 114 |
# File 'lib/ruck/shred.rb', line 112 def finished? @fiber.nil? end |
#kill ⇒ Object
120 121 122 |
# File 'lib/ruck/shred.rb', line 120 def kill @fiber = nil end |
#pause ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/ruck/shred.rb', line 90 def pause return unless Shred.current == self @@current_shreds.pop Fiber.yield end |
#running? ⇒ Boolean
116 117 118 |
# File 'lib/ruck/shred.rb', line 116 def running? !finished? end |