Class: Goru::Routine
- Inherits:
-
Object
- Object
- Goru::Routine
- Includes:
- Is::Handler
- Defined in:
- lib/goru/routine.rb
Overview
- public
Direct Known Subclasses
Goru::Routines::Bridge, Goru::Routines::Channel, Goru::Routines::IO
Instance Attribute Summary collapse
-
#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.
-
#reactor=(reactor) ⇒ Object
[public].
-
#result ⇒ Object
[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.
18 19 20 21 22 23 |
# File 'lib/goru/routine.rb', line 18 def initialize(state = nil, &block) @state = state @block = block set_status(:ready) @result, @error, @reactor = nil end |
Instance Attribute Details
#state ⇒ Object (readonly)
- public
27 28 29 |
# File 'lib/goru/routine.rb', line 27 def state @state end |
#status ⇒ Object (readonly)
- public
27 28 29 |
# File 'lib/goru/routine.rb', line 27 def status @status end |
Instance Method Details
#call ⇒ Object
- public
38 39 40 41 42 43 44 |
# File 'lib/goru/routine.rb', line 38 def call @block.call(self) rescue => error @error = error set_status(:errored) trigger(error) end |
#finished(result = nil) ⇒ Object
- public
48 49 50 51 52 53 |
# File 'lib/goru/routine.rb', line 48 def finished(result = nil) unless @finished @result = result set_status(:finished) end end |
#reactor=(reactor) ⇒ Object
- public
31 32 33 34 |
# File 'lib/goru/routine.rb', line 31 def reactor=(reactor) @reactor = reactor status_changed end |
#result ⇒ Object
- public
63 64 65 66 67 68 69 70 |
# File 'lib/goru/routine.rb', line 63 def result case @status when :errored raise @error else @result end end |
#sleep(seconds) ⇒ Object
- public
74 75 76 77 |
# File 'lib/goru/routine.rb', line 74 def sleep(seconds) set_status(:idle) @reactor.routine_asleep(self, seconds) end |
#update(state) ⇒ Object
- public
57 58 59 |
# File 'lib/goru/routine.rb', line 57 def update(state) @state = state end |
#wake ⇒ Object
- public
81 82 83 |
# File 'lib/goru/routine.rb', line 81 def wake set_status(:ready) end |