Module: Green::GreenMethods

Included in:
Green, Proxy
Defined in:
lib/green.rb

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object



30
31
32
# File 'lib/green.rb', line 30

def [](name)
  locals[name]
end

#[]=(name, val) ⇒ Object



34
35
36
# File 'lib/green.rb', line 34

def []=(name, val)
  locals[name] = val
end

#killObject



22
23
24
# File 'lib/green.rb', line 22

def kill
  self.throw(GreenKill.new)
end

#localsObject



26
27
28
# File 'lib/green.rb', line 26

def locals
  f.local_fiber_variables
end

#schedule(*args) ⇒ Object Also known as: call



38
39
40
# File 'lib/green.rb', line 38

def schedule(*args)
  Green.hub.callback { self.switch(*args) }
end

#switch(*args) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/green.rb', line 10

def switch(*args)
  f.transfer(*args).tap do |*res|
    if res.size == 1 && res.first.is_a?(ThrowException)
      raise(res.first.exc)
    end
  end
end

#throw(exc = RuntimeException.new) ⇒ Object



18
19
20
# File 'lib/green.rb', line 18

def throw(exc = RuntimeException.new)
  Green.hub.callback { switch(ThrowException.new exc) }
end