Method: Contender::ExecutorService#invoke_all

Defined in:
lib/contender/executor_service.rb

#invoke_all(tasks) ⇒ Array<FutureTask>

Parameters:

  • tasks (Array<Object>)

Returns:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/contender/executor_service.rb', line 52

def invoke_all(tasks)
  finished = false
  futures = Array.new

  begin
    tasks.each do |task|
      future = create_task_for task

      futures.push future
      execute future
    end

    futures.each do |future|
      unless future.done?
        begin
          future.result
        rescue CancellationError
        rescue ExecutionError
          # The caller can deal with these errors
        end
      end
    end

    finished = true
    futures
  ensure
    unless finished
      futures.each do |future|
        future.cancel true
      end
    end
  end
end