Skip to content

Commit a671f30

Browse files
committed
print result in thread pool example
1 parent e6a9719 commit a671f30

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

demo/demo_thread_pool.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@
6161
runtime = Benchmark.measure do
6262
# create a thread pool of 4 threads with a persistent connection to serpapi.com
6363
pool = ConnectionPool.new(size: n, timeout: 5) do
64-
SerpApi::Client.new(engine: 'google', api_key: ENV.fetch('SERPAPI_KEY', nil), timeout: 30, persistent: true)
64+
SerpApi::Client.new(engine: 'google', api_key: ENV['SERPAPI_KEY'], timeout: 30, persistent: true)
6565
end
6666

6767
# run user thread to search for your favorites coffee type
6868
threads = %w[latte espresso cappuccino americano mocha macchiato frappuccino cold_brew].map do |query|
6969
Thread.new do
70-
pool.with { |socket| socket.search({ q: query }).to_s }
70+
pool.with do|socket|
71+
results = socket.search({ q: query })
72+
puts "first result title: #{results[:organic_results].first[:title]} for query: #{results[:search_parameters][:q]}"
73+
end
7174
end
7275
end
7376
threads.map(&:value)

0 commit comments

Comments
 (0)