Module: Enumerable

Defined in:
lib/stack-service-base/async_helpers.rb

Overview

require ‘async’

Instance Method Summary collapse

Instance Method Details

#map_asyncObject



5
6
7
8
9
10
11
12
13
# File 'lib/stack-service-base/async_helpers.rb', line 5

def map_async
  results = Array.new(self.size)
  self.each_with_index.map do |item, index|
    Async do
      results[index] = item.respond_to?(:to_ary) ? yield(*item.to_ary) : yield(item)
    end
  end.map(&:wait)
  results
end