Class: Contender::Pool::Task
- Inherits:
-
Object
- Object
- Contender::Pool::Task
- Defined in:
- lib/contender/pool/task.rb
Overview
Encapsulates a task that is either waiting for execution or has been executed
Instance Attribute Summary collapse
-
#arguments ⇒ Array
readonly
The arguments that the block will be executed with.
-
#block ⇒ Proc
readonly
The block that will be executed by a pool worker.
-
#exception ⇒ Exception
readonly
Exception that occured during task execution.
Instance Method Summary collapse
-
#execute ⇒ undefined
Executes the block with the provided arguments.
-
#executed? ⇒ Boolean
Returns true if this task has been executed.
-
#failed? ⇒ Boolean
Returns true if the execution of this task resulted in an exception.
- #initialize(block, arguments) ⇒ undefined constructor
Constructor Details
#initialize(block, arguments) ⇒ undefined
17 18 19 20 21 |
# File 'lib/contender/pool/task.rb', line 17 def initialize(block, arguments) @block = block @arguments = arguments @executed = false end |
Instance Attribute Details
#arguments ⇒ Array (readonly)
Returns The arguments that the block will be executed with.
6 7 8 |
# File 'lib/contender/pool/task.rb', line 6 def arguments @arguments end |
#block ⇒ Proc (readonly)
Returns The block that will be executed by a pool worker.
9 10 11 |
# File 'lib/contender/pool/task.rb', line 9 def block @block end |
#exception ⇒ Exception (readonly)
Returns Exception that occured during task execution.
12 13 14 |
# File 'lib/contender/pool/task.rb', line 12 def exception @exception end |
Instance Method Details
#execute ⇒ undefined
Executes the block with the provided arguments
41 42 43 44 45 46 47 48 49 |
# File 'lib/contender/pool/task.rb', line 41 def execute begin @block.call *@arguments rescue Exception => exception @exception = exception end @executed = true end |
#executed? ⇒ Boolean
Returns true if this task has been executed
27 28 29 |
# File 'lib/contender/pool/task.rb', line 27 def executed? @executed end |
#failed? ⇒ Boolean
Returns true if the execution of this task resulted in an exception
35 36 37 |
# File 'lib/contender/pool/task.rb', line 35 def failed? !!@exception end |