module TwitterFriendly::REST::Parallel

Public Instance Methods

parallel(options = {}) { |batch| ... } click to toggle source
# File lib/twitter_friendly/rest/parallel.rb, line 4
def parallel(options = {}, &block)
  batch = Arguments.new
  yield(batch)

  in_threads = options.fetch(:in_threads, batch.size)

  ::Parallel.map_with_index(batch, in_threads: in_threads) do |args, i|
    {i: i, result: send(*args)} # Cached here
  end.sort_by { |q| q[:i] }.map { |q| q[:result] }
end