class Goru::Routine

public

Attributes

reactor[W]
public
state[R]
public
status[R]
public

Public Class Methods

new(state = nil, &block) click to toggle source
# File lib/goru/routine.rb, line 7
def initialize(state = nil, &block)
  @state = state
  @block = block
  @status = :running
  @result, @error, @reactor = nil
end

Public Instance Methods

call() click to toggle source
public
# File lib/goru/routine.rb, line 30
def call
  @block.call(self)
rescue => error
  puts "[routine error] #{error}"
  puts error.backtrace

  @error = error
  @status = :errored
end
finished(result = nil) click to toggle source
public
# File lib/goru/routine.rb, line 42
def finished(result = nil)
  unless @finished
    @result = result
    @status = :finished
  end
end
result() click to toggle source
public
# File lib/goru/routine.rb, line 57
def result
  case @status
  when :errored
    raise @error
  else
    @result
  end
end
running?() click to toggle source
public
# File lib/goru/routine.rb, line 24
def running?
  @status == :running
end
sleep(seconds) click to toggle source
public
# File lib/goru/routine.rb, line 68
def sleep(seconds)
  @status = :sleeping
  @reactor.sleep(self, seconds)
end
update(state) click to toggle source
public
# File lib/goru/routine.rb, line 51
def update(state)
  @state = state
end
wake() click to toggle source
public
# File lib/goru/routine.rb, line 75
def wake
  @status = :running
end