In [1]:
# Pkg.add("Requests")
using Requests
In [2]:
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
Out[2]:
do_search (generic function with 1 method)
In [3]:
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
Out[3]:
main (generic function with 1 method)
In [4]:
main()
Google0.921427654Response(200 OK, 16 headers, 52069 bytes in body)
In [5]:
main()
Bing0.770564858Response(200 OK, 13 headers, 90888 bytes in body)
In [6]:
main()
Bing0.648154419Response(200 OK, 13 headers, 89350 bytes in body)
In [7]:
main()
Google0.764888553Response(200 OK, 16 headers, 52006 bytes in body)
In [8]:
main()
Google0.642048228Response(200 OK, 16 headers, 51923 bytes in body)
In [9]:
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
Out[9]:
main2 (generic function with 1 method)
In [10]:
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)
In [ ]: