Skip to content

Instantly share code, notes, and snippets.

@JamesAndresCM
Created May 31, 2022 03:04
Show Gist options
  • Save JamesAndresCM/8e106f30f5ecde93cc07bad71a7d8b0d to your computer and use it in GitHub Desktop.
Save JamesAndresCM/8e106f30f5ecde93cc07bad71a7d8b0d to your computer and use it in GitHub Desktop.

Async Proccess Elixir

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}"))

Async Proccess Ruby 3

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)) }} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment