# Pkg.add("Requests")
using Requests
function do_search(results::Channel{Tuple{String, Float64, HttpCommon.Response}}, engine::String, url::String)
res, exec_time = @timed get(url)
if isopen(results)
put!(results, (engine, exec_time, res))
end
end
do_search (generic function with 1 method)
function main()
results = Channel{Tuple{String, Float64, HttpCommon.Response}}(3)
searches = [
"Yahoo"=>"https://search.yahoo.co.jp/search?p=julialang",
"Google"=>"https://www.google.co.jp/search?q=julialang",
"Bing"=>"https://www.bing.com/search?q=julialang"]
for (engine, url) = searches
@schedule do_search(results, engine, url)
end
res0 = take!(results)
close(results)
println(res0...)
end
main (generic function with 1 method)
main()
Google0.921427654Response(200 OK, 16 headers, 52069 bytes in body)
main()
Bing0.770564858Response(200 OK, 13 headers, 90888 bytes in body)
main()
Bing0.648154419Response(200 OK, 13 headers, 89350 bytes in body)
main()
Google0.764888553Response(200 OK, 16 headers, 52006 bytes in body)
main()
Google0.642048228Response(200 OK, 16 headers, 51923 bytes in body)
function main2()
results = Channel{Tuple{String, Float64, HttpCommon.Response}}(3)
searches = [
"Yahoo"=>"https://search.yahoo.co.jp/search?p=julialang",
"Google"=>"https://www.google.co.jp/search?q=julialang",
"Bing"=>"https://www.bing.com/search?q=julialang"]
for (engine, url) = searches
@schedule do_search(results, engine, url)
end
res1 = take!(results)
println(res1...)
res2 = take!(results)
println(res2...)
res3 = take!(results)
println(res3...)
close(results)
end
main2 (generic function with 1 method)
main2()
Google0.685931991Response(200 OK, 16 headers, 52070 bytes in body) Bing0.691108047Response(200 OK, 13 headers, 91184 bytes in body) Yahoo1.240782096Response(200 OK, 14 headers, 10487 bytes in body)