Sunday, November 7, 2021

Async Ruby#brunosutic.com

From Bruno Sutic's blog:

Ruby has an Async implementation!

It's available today, it's production-ready, and it's probably the most awesome thing that's happened to Ruby in the last decade, if not longer.

Pretty big news for the Ruby language!

Here's a code snippet of how this works.

require "async"
require "open-uri"
require "httparty"

start = Time.now

Async do |task|
  task.async do
    URI.open("https://httpbin.org/delay/1.6")
  end

  task.async do
    HTTParty.get("https://httpbin.org/delay/1.6")
  end
end

puts "Duration: #{Time.now - start}"

Seems like a nice simple syntax.