Skip to content

Instantly share code, notes, and snippets.

@Mon-Ouie
Created June 24, 2011 11:15
Show Gist options
  • Save Mon-Ouie/1044590 to your computer and use it in GitHub Desktop.
Save Mon-Ouie/1044590 to your computer and use it in GitHub Desktop.
module Enumerable
def threaded_each(n = 30, &block)
each_slice(n) do |elems|
elems.map { |o| Thread.new(o, &block) }.each(&:join)
end
end
end
(1..100_000).threaded_each do |n|
puts n
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment