run_query = fn query_def -> Process.sleep(2000); "#{query_def} result" end
async_query = fn query_def -> spawn(fn -> IO.puts(run_query.(query_def)) end) end
Enum.each(1..5, &async_query.("query #{&1}"))
require 'async'
run_query = -> (val) { sleep(2); "query #{val} result" }
async_query = ->(val) { run_query.(val) }
Async {|task| (1..5).each{|el| task.async { puts(async_query.(el)) }} }