Skip to content

Instantly share code, notes, and snippets.

module Enumerable
def first_to_finish
threads = collect { |args| Thread.new { yield(args) } }
loop until done = threads.detect { |t| !t.alive? }
threads.each(&:kill)
done.value
end
end
puts [5, 3, 1, 2, 4].first_to_finish { |x| sleep x }
@cheeaun
cheeaun / rdrc2012.md
Created May 19, 2012 14:45
RedDotRubyConf 2012 links & resources