class FiberRecycling::Fiber

Attributes

backend[R]

Public Class Methods

current() click to toggle source
# File lib/fiber_recycling/fiber.rb, line 4
def self.current
  Thread.current[:fiber_recycling__fiber] || root
end
new(backend = nil, &block) click to toggle source
# File lib/fiber_recycling/fiber.rb, line 25
def initialize(backend = nil, &block)
  if backend && backend.is_a?(FiberBackend)
    @backend = backend
  else
    raise ArgumentError, 'must pass a block' unless block_given?
    @backend = NormalFiberBackend.new(self, block)
  end
end
root() click to toggle source
# File lib/fiber_recycling/fiber.rb, line 8
def self.root
  unless Thread.current.thread_variable_get(:fiber_recycling__root_fiber)
    Thread.current.thread_variable_set(:fiber_recycling__root_fiber, new(RootFiberBackend.new))
  end
  Thread.current.thread_variable_get(:fiber_recycling__root_fiber)
end
root?() click to toggle source
# File lib/fiber_recycling/fiber.rb, line 15
def self.root?
  current == root
end
yield(*args) click to toggle source
# File lib/fiber_recycling/fiber.rb, line 19
def self.yield(*args)
  current.backend.class.yield(*args)
end

Public Instance Methods

alive?() click to toggle source
# File lib/fiber_recycling/fiber.rb, line 34
def alive?
  @backend.alive?
end
inspect() click to toggle source
# File lib/fiber_recycling/fiber.rb, line 38
def inspect
  to_s
end
resume(*args) click to toggle source
# File lib/fiber_recycling/fiber.rb, line 42
def resume(*args)
  @backend.resume(*args)
end
to_s() click to toggle source
# File lib/fiber_recycling/fiber.rb, line 46
def to_s
  @backend.to_s
end
transfer(*args) click to toggle source
# File lib/fiber_recycling/fiber.rb, line 50
def transfer(*args)
  @backend.transfer(*args)
end
variables() click to toggle source
# File lib/fiber_recycling/fiber.rb, line 54
def variables
  @backend.variables
end