Class: Goru::Routine
- Inherits:
-
Object
- Object
- Goru::Routine
- Defined in:
- lib/goru/routine.rb
Overview
- public
Direct Known Subclasses
Instance Attribute Summary collapse
-
#reactor ⇒ Object
writeonly
[public].
-
#state ⇒ Object
readonly
[public].
-
#status ⇒ Object
readonly
[public].
Instance Method Summary collapse
-
#call ⇒ Object
[public].
-
#finished(result = nil) ⇒ Object
[public].
-
#initialize(state = nil, &block) ⇒ Routine
constructor
A new instance of Routine.
-
#result ⇒ Object
[public].
-
#running? ⇒ Boolean
[public].
-
#sleep(seconds) ⇒ Object
[public].
-
#update(state) ⇒ Object
[public].
-
#wake ⇒ Object
[public].
Constructor Details
#initialize(state = nil, &block) ⇒ Routine
Returns a new instance of Routine.
7 8 9 10 11 12 |
# File 'lib/goru/routine.rb', line 7 def initialize(state = nil, &block) @state = state @block = block @status = :running @result, @error, @reactor = nil end |
Instance Attribute Details
#reactor=(value) ⇒ Object (writeonly)
- public
20 21 22 |
# File 'lib/goru/routine.rb', line 20 def reactor=(value) @reactor = value end |
#state ⇒ Object (readonly)
- public
16 17 18 |
# File 'lib/goru/routine.rb', line 16 def state @state end |
#status ⇒ Object (readonly)
- public
16 17 18 |
# File 'lib/goru/routine.rb', line 16 def status @status end |
Instance Method Details
#call ⇒ Object
- public
30 31 32 33 34 35 36 37 38 |
# 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) ⇒ Object
- public
42 43 44 45 46 47 |
# File 'lib/goru/routine.rb', line 42 def finished(result = nil) unless @finished @result = result @status = :finished end end |
#result ⇒ Object
- public
57 58 59 60 61 62 63 64 |
# File 'lib/goru/routine.rb', line 57 def result case @status when :errored raise @error else @result end end |
#running? ⇒ Boolean
- public
24 25 26 |
# File 'lib/goru/routine.rb', line 24 def running? @status == :running end |
#sleep(seconds) ⇒ Object
- public
68 69 70 71 |
# File 'lib/goru/routine.rb', line 68 def sleep(seconds) @status = :sleeping @reactor.sleep(self, seconds) end |
#update(state) ⇒ Object
- public
51 52 53 |
# File 'lib/goru/routine.rb', line 51 def update(state) @state = state end |
#wake ⇒ Object
- public
75 76 77 |
# File 'lib/goru/routine.rb', line 75 def wake @status = :running end |