Skip to content

Commit df16fde

Browse files
committed
<< -> map
1 parent 13e5d59 commit df16fde

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

examples/threaded.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
require 'mysql2'
55
require 'timeout'
66

7-
threads = []
87
# Should never exceed worst case 3.5 secs across all 20 threads
98
Timeout.timeout(3.5) do
10-
20.times do
11-
threads << Thread.new do
9+
20.times.map do
10+
Thread.new do
1211
overhead = rand(3)
1312
puts ">> thread #{Thread.current.object_id} query, #{overhead} sec overhead"
1413
# 3 second overhead per query
1514
Mysql2::Client.new(:host => "localhost", :username => "root").query("SELECT sleep(#{overhead}) as result")
1615
puts "<< thread #{Thread.current.object_id} result, #{overhead} sec overhead"
1716
end
18-
end
19-
threads.each{|t| t.join }
20-
end
17+
end.each(&:join)
18+
end

0 commit comments

Comments
 (0)