Class: Mcoin::Parallel

Inherits:
Object
  • Object
show all
Defined in:
lib/mcoin/parallel.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.async(array, method, &block) ⇒ Object



13
14
15
16
17
# File 'lib/mcoin/parallel.rb', line 13

def async(array, method, &block)
  array.each do |item|
    Thread.new { yield item.send(method) }
  end
end

.map(array, method) ⇒ Object



7
8
9
10
11
# File 'lib/mcoin/parallel.rb', line 7

def map(array, method)
  array.map do |item|
    Thread.new { item.send(method) }
  end.map(&:join).map(&:value)
end