Class: Goru::Routine
- Inherits:
-
Object
- Object
- Goru::Routine
- Includes:
- Is::Handler
- Defined in:
- lib/goru/routine.rb
Overview
- public
Direct Known Subclasses
Instance Attribute Summary collapse
-
#debug ⇒ Object
writeonly
[public].
-
#error ⇒ Object
readonly
[public].
-
#state ⇒ Object
readonly
[public].
-
#status ⇒ Object
readonly
[public].
Instance Method Summary collapse
-
#adopted ⇒ Object
[public].
-
#call ⇒ Object
[public].
-
#finished(result = nil) ⇒ Object
[public].
-
#initialize(state = nil, &block) ⇒ Routine
constructor
A new instance of Routine.
-
#reactor=(reactor) ⇒ Object
[public].
-
#ready? ⇒ Boolean
[public].
-
#result ⇒ Object
[public].
-
#sleep(seconds) ⇒ Object
[public].
-
#update(state) ⇒ Object
[public].
Constructor Details
#initialize(state = nil, &block) ⇒ Routine
Returns a new instance of Routine.
20 21 22 23 24 25 26 |
# File 'lib/goru/routine.rb', line 20 def initialize(state = nil, &block) @state = state @block = block set_status(:ready) @result, @error, @reactor = nil @debug = true end |
Instance Attribute Details
#debug=(value) ⇒ Object (writeonly)
- public
34 35 36 |
# File 'lib/goru/routine.rb', line 34 def debug=(value) @debug = value end |
#error ⇒ Object (readonly)
- public
30 31 32 |
# File 'lib/goru/routine.rb', line 30 def error @error end |
#state ⇒ Object (readonly)
- public
30 31 32 |
# File 'lib/goru/routine.rb', line 30 def state @state end |
#status ⇒ Object (readonly)
- public
30 31 32 |
# File 'lib/goru/routine.rb', line 30 def status @status end |
Instance Method Details
#adopted ⇒ Object
- public
114 115 116 |
# File 'lib/goru/routine.rb', line 114 def adopted # noop end |
#call ⇒ Object
- public
45 46 47 48 49 50 51 |
# File 'lib/goru/routine.rb', line 45 def call @block.call(self) rescue => error @error = error set_status(:errored) trigger(error) end |
#finished(result = nil) ⇒ Object
- public
55 56 57 58 59 60 |
# File 'lib/goru/routine.rb', line 55 def finished(result = nil) @result = result set_status(:finished) throw :continue end |
#reactor=(reactor) ⇒ Object
- public
38 39 40 41 |
# File 'lib/goru/routine.rb', line 38 def reactor=(reactor) @reactor = reactor status_changed end |
#ready? ⇒ Boolean
- public
92 93 94 |
# File 'lib/goru/routine.rb', line 92 def ready? @status == :ready end |
#result ⇒ Object
- public
70 71 72 73 74 75 76 77 |
# File 'lib/goru/routine.rb', line 70 def result case @status when :errored raise @error else @result end end |
#sleep(seconds) ⇒ Object
- public
81 82 83 84 85 86 87 88 |
# File 'lib/goru/routine.rb', line 81 def sleep(seconds) set_status(:idle) @reactor.asleep_for(seconds) do set_status(:ready) end throw :continue end |
#update(state) ⇒ Object
- public
64 65 66 |
# File 'lib/goru/routine.rb', line 64 def update(state) @state = state end |