We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
<<
map
1 parent 13e5d59 commit df16fdeCopy full SHA for df16fde
examples/threaded.rb
@@ -4,17 +4,15 @@
4
require 'mysql2'
5
require 'timeout'
6
7
-threads = []
8
# Should never exceed worst case 3.5 secs across all 20 threads
9
Timeout.timeout(3.5) do
10
- 20.times do
11
- threads << Thread.new do
+ 20.times.map do
+ Thread.new do
12
overhead = rand(3)
13
puts ">> thread #{Thread.current.object_id} query, #{overhead} sec overhead"
14
# 3 second overhead per query
15
Mysql2::Client.new(:host => "localhost", :username => "root").query("SELECT sleep(#{overhead}) as result")
16
puts "<< thread #{Thread.current.object_id} result, #{overhead} sec overhead"
17
end
18
- end
19
- threads.each{|t| t.join }
20
-end
+ end.each(&:join)
+end
0 commit comments