Skip to content

Commit

Permalink
Add Map/Reduce example
Browse files Browse the repository at this point in the history
  • Loading branch information
dasch committed May 28, 2010
1 parent 937985b commit 9b782d9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/mapreduce.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'minx'

def map
output = Minx.channel
Minx.spawn { loop { output.write(rand(100)) } }
return output
end

def reduce(*inputs, output)
Minx.spawn do
loop do
sum = 0
10.times { sum += Minx.select(*inputs) }
output.write(sum)
end
end
end

inputs = (0...10).map { map }
output = Minx.channel

reduce(*inputs, output)

puts output.read
puts output.read

0 comments on commit 9b782d9

Please sign in to comment.