Parent

Class Index [+]

Quicksearch

Fiber

Attributes

yield[R]
thread[R]

Public Class Methods

new() click to toggle source
    # File lib/ramaze/snippets/fiber.rb, line 7
 7:     def initialize
 8:       raise ArgumentError, 'new Fiber requires a block' unless block_given?
 9: 
10:       @yield = Queue.new
11:       @resume = Queue.new
12: 
13:       @thread = Thread.new{ @yield.push [*yield(*wait)] }
14:       @thread.abort_on_exception = true
15:       @thread[:fiber] = self
16:     end
yield(*args) click to toggle source
    # File lib/ramaze/snippets/fiber.rb, line 30
30:     def self.yield *args
31:       raise FiberError, "can't yield from root fiber" unless fiber = Thread.current[:fiber]
32:       fiber.yield.push(args)
33:       result = fiber.wait
34:       result.size > 1 ? result : result.first
35:     end

Public Instance Methods

inspect() click to toggle source
    # File lib/ramaze/snippets/fiber.rb, line 37
37:     def inspect
38:       "#<#{self.class}:0x#{self.object_id.to_s(16)}>"
39:     end
resume(*args) click to toggle source
    # File lib/ramaze/snippets/fiber.rb, line 19
19:     def resume *args
20:       raise FiberError, 'dead fiber called' unless @thread.alive?
21:       @resume.push(args)
22:       result = @yield.pop
23:       result.size > 1 ? result : result.first
24:     end
wait() click to toggle source
    # File lib/ramaze/snippets/fiber.rb, line 26
26:     def wait
27:       @resume.pop
28:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.