Parent

Class/Module Index [+]

Quicksearch

Fiber

Attributes

thread[R]
yield[R]

Public Class Methods

new() click to toggle source
# File lib/ramaze/snippets/fiber.rb, line 7
def initialize
  raise ArgumentError, 'new Fiber requires a block' unless block_given?

  @yield = Queue.new
  @resume = Queue.new

  @thread = Thread.new{ @yield.push [*yield(*wait)] }
  @thread.abort_on_exception = true
  @thread[:fiber] = self
end
yield(*args) click to toggle source
# File lib/ramaze/snippets/fiber.rb, line 30
def self.yield *args
  raise FiberError, "can't yield from root fiber" unless fiber = Thread.current[:fiber]
  fiber.yield.push(args)
  result = fiber.wait
  result.size > 1 ? result : result.first
end

Public Instance Methods

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.