Class: Concurrent::SafeTaskExecutor
- Inherits:
-
Object
- Object
- Concurrent::SafeTaskExecutor
- Defined in:
- lib/concurrent/safe_task_executor.rb
Overview
A simple utility class that executes a callable and returns and array of three elements: success - indicating if the callable has been executed without errors value - filled by the callable result if it has been executed without errors, nil otherwise reason - the error risen by the callable if it has been executed with errors, nil otherwise
Instance Method Summary collapse
- #execute ⇒ Array
-
#initialize(task) ⇒ SafeTaskExecutor
constructor
A new instance of SafeTaskExecutor.
Constructor Details
#initialize(task) ⇒ SafeTaskExecutor
Returns a new instance of SafeTaskExecutor.
8 9 10 |
# File 'lib/concurrent/safe_task_executor.rb', line 8 def initialize(task) @task = task end |
Instance Method Details
#execute ⇒ Array
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/concurrent/safe_task_executor.rb', line 13 def execute success = false value = reason = nil begin value = @task.call success = true rescue => ex reason = ex success = false end [success, value, reason] end |