Parent

Files

Fiber

Attributes

thread[R]

Public Class Methods

current() click to toggle source
    # File lib/moqueue/fibers18.rb, line 47
47:     def self.current
48:       Thread.current[:fiber] or raise FiberError, 'not inside a fiber'
49:     end
new() click to toggle source
    # File lib/moqueue/fibers18.rb, line 8
 8:     def initialize
 9:       raise ArgumentError, 'new Fiber requires a block' unless block_given?
10: 
11:       @yield = Queue.new
12:       @resume = Queue.new
13: 
14:       @thread = Thread.new{ @yield.push [ *yield(*@resume.pop) ] }
15:       @thread.abort_on_exception = true
16:       @thread[:fiber] = self
17:     end
yield(*args) click to toggle source
    # File lib/moqueue/fibers18.rb, line 42
42:     def self.yield *args
43:       raise FiberError, "can't yield from root fiber" unless fiber = Thread.current[:fiber]
44:       fiber.yield(*args)
45:     end

Public Instance Methods

alive?() click to toggle source
    # File lib/moqueue/fibers18.rb, line 20
20:     def alive?
21:       @thread.alive?
22:     end
inspect() click to toggle source
    # File lib/moqueue/fibers18.rb, line 51
51:     def inspect
52:       "#<#{self.class}:0x#{self.object_id.to_s(16)}>"
53:     end
resume(*args) click to toggle source
    # File lib/moqueue/fibers18.rb, line 24
24:     def resume *args
25:       raise FiberError, 'dead fiber called' unless @thread.alive?
26:       raise FiberError, 'double resume' if @thread == Thread.current
27:       @resume.push(args)
28:       result = @yield.pop
29:       result.size > 1 ? result : result.first
30:     end
resume!() click to toggle source
    # File lib/moqueue/fibers18.rb, line 32
32:     def resume!
33:       @resume.push []
34:     end
yield(*args) click to toggle source
    # File lib/moqueue/fibers18.rb, line 36
36:     def yield *args
37:       @yield.push(args)
38:       result = @resume.pop
39:       result.size > 1 ? result : result.first
40:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.