Class: NeverBlock::Fiber

Inherits:
Fiber
  • Object
show all
Defined in:
lib/neverblock/core/fiber.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(neverblock = true, &block) ⇒ Fiber

Returns a new instance of Fiber.



10
11
12
13
# File 'lib/neverblock/core/fiber.rb', line 10

def initialize(neverblock = true, &block)
  self[:neverblock] = neverblock
  super()
end

Class Method Details

.yield(*args) ⇒ Object

Sending an exception instance to resume will yield the fiber and then raise the exception. This is necessary to raise exceptions in their correct context.



32
33
34
35
36
# File 'lib/neverblock/core/fiber.rb', line 32

def self.yield(*args)
  result = super
  raise result if result.is_a? Exception
  result
end

Instance Method Details

#[](key) ⇒ Object

Attribute Reference–Returns the value of a fiber-local variable, using either a symbol or a string name. If the specified variable does not exist, returns nil.



19
20
21
# File 'lib/neverblock/core/fiber.rb', line 19

def [](key)
  local_fiber_variables[key]
end

#[]=(key, value) ⇒ Object

Attribute Assignment–Sets or creates the value of a fiber-local variable, using either a symbol or a string. See also Fiber#[].



25
26
27
# File 'lib/neverblock/core/fiber.rb', line 25

def []=(key,value)
  local_fiber_variables[key] = value
end