class Concurrent::SafeTaskExecutor
reason - the error risen by the callable if it has been executed with errors, nil otherwise
value - filled by the callable result if it has been executed without errors, nil otherwise
success - indicating if the callable has been executed without errors
A simple utility class that executes a callable and returns and array of three elements:
def execute(*args)
-
(Array)
-
def execute(*args) @mutex.synchronize do success = false value = reason = nil begin value = @task.call(*args) success = true rescue @exception_class => ex reason = ex success = false end [success, value, reason] end end
def initialize(task, opts = {})
def initialize(task, opts = {}) @task = task @mutex = Mutex.new @exception_class = opts.fetch(:rescue_exception, false) ? Exception : StandardError end