Ruby Threads
Hackers love threads. It eats computers, hard to manage, but it makes things fast.. Not just fast, fucking fast. If we’re downloading all the images on some website, but they only allow a fixed number of imgs / page. Then a non-threaded application would be “request page 1 -> server gives page 1 -> request page 2 -> server gives page 2…”.. A threaded application would be: “request everything -> (if the server doesn’t die) server gives everything”
Things aren’t instant on the internet, so you save huge on round trip ping times by threading.
There aren’t good examples on how to do it properly on the internet, so i’ll save you:
watch the output, and learn.
threads = []
threads << Thread.new{
(1..10).each do |x|
sleep(Random.rand(2))
puts “job #{x} completed”
end
}
threads.each(&:join)