Module: TwitterFriendly::REST::Parallel

Included in:
API
Defined in:
lib/twitter_friendly/rest/parallel.rb

Defined Under Namespace

Classes: Arguments

Instance Method Summary collapse

Instance Method Details

#parallel(options = {}) {|batch| ... } ⇒ Object

Yields:

  • (batch)


4
5
6
7
8
9
10
11
12
13
# 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