Method: Twitter::Utils.pmap

Defined in:
lib/twitter/utils.rb

.pmap(enumerable, &block) ⇒ Array, Enumerator

Returns a new array with the results of running block once for every element in enumerable. If no block is given, an enumerator is returned instead.

Parameters:

Returns:

  • (Array, Enumerator)


21
22
23
24
25
26
27
28
29
# File 'lib/twitter/utils.rb', line 21

def pmap(enumerable, &block)
  return to_enum(:pmap, enumerable) unless block

  if enumerable.count == 1
    enumerable.collect(&block)
  else
    enumerable.collect { |object| Thread.new { yield(object) } }.collect(&:value)
  end
end