Class: Procrastinate::Task::Result
- Inherits:
-
Object
- Object
- Procrastinate::Task::Result
- Defined in:
- lib/procrastinate/task/result.rb
Overview
A single value result, like from a normal method call. Return an instance of this from your task#result method to enable result handling.
Instance Method Summary collapse
-
#incoming_message(obj) ⇒ Object
Gets passed all messages sent by the child process for this task.
-
#initialize ⇒ Result
constructor
A new instance of Result.
-
#process_died ⇒ Object
Notifies this result that the process has died.
- #ready? ⇒ Boolean
- #value ⇒ Object
Constructor Details
#initialize ⇒ Result
Returns a new instance of Result.
8 9 10 11 12 |
# File 'lib/procrastinate/task/result.rb', line 8 def initialize @value_ready = Procrastinate::Utils::OneTimeFlag.new @value = nil @exception = false end |
Instance Method Details
#incoming_message(obj) ⇒ Object
Gets passed all messages sent by the child process for this task.
*control thread*
17 18 19 20 21 22 |
# File 'lib/procrastinate/task/result.rb', line 17 def (obj) return if ready? @value = obj @value_ready.set end |
#process_died ⇒ Object
Notifies this result that the process has died. If this happens before a process result is passed to #incoming_message, that message will never arrive.
*control thread*
29 30 31 32 33 34 |
# File 'lib/procrastinate/task/result.rb', line 29 def process_died return if ready? @exception = true @value_ready.set end |
#ready? ⇒ Boolean
46 47 48 |
# File 'lib/procrastinate/task/result.rb', line 46 def ready? @value_ready.set? end |
#value ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/procrastinate/task/result.rb', line 36 def value @value_ready.wait if @exception raise Procrastinate::ChildDeath, "Child process died before producing a value." else @value end end |