Module: TwitterWithAutoPagination::Parallel

Included in:
Client
Defined in:
lib/twitter_with_auto_pagination/parallel.rb

Defined Under Namespace

Classes: Arguments

Instance Method Summary collapse

Instance Method Details

#fetch_parallelly(signatures) ⇒ Object

Deprecated

:friends, args: [‘ts_3156’, …], {…


38
39
40
41
42
# File 'lib/twitter_with_auto_pagination/parallel.rb', line 38

def fetch_parallelly(signatures)
  ::Parallel.map_with_index(signatures, in_threads: signatures.size) do |signature, i|
    {i: i, result: send(signature[:method], *signature[:args])}
  end.sort_by { |q| q[:i] }.map { |q| q[:result] }
end

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

Yields:

  • (batch)


6
7
8
9
10
11
12
13
14
15
# File 'lib/twitter_with_auto_pagination/parallel.rb', line 6

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)}
  end.sort_by { |q| q[:i] }.map { |q| q[:result] }
end