Skip to content

Instantly share code, notes, and snippets.

@maasha
Last active August 29, 2015 14:07
Show Gist options
  • Save maasha/0ab9c18880e2a84dacaa to your computer and use it in GitHub Desktop.
Save maasha/0ab9c18880e2a84dacaa to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'pp'
input = (0 .. 10).to_enum
enums = [input]
threads = []
10.times do |i|
enums << Enumerator.new do |output|
threads << Thread.new(enums[i], output) do |i, o|
i.each { |e| o << (e + 1) }
end
end
end
enums.last.each { |e| p e }
threads.each { |t| t.join }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment