Sha256: 0f91f46e840eca1cb12b7155e3a1bca3d877ea9f9a6c1556fe08f1af5cda69eb

Contents?: true

Size: 751 Bytes

Versions: 26

Compression:

Stored size: 751 Bytes

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony'
require 'httparty'
require 'json'

def get_time(tzone)
  res = HTTParty.get("http://worldtimeapi.org/api/timezone/#{tzone}")
  return '- failed -' unless res.ok?

  json = JSON.parse(res.body)
  Time.parse(json['datetime'])
end

zones = %w{
  Europe/London Europe/Paris Europe/Bucharest America/New_York Asia/Bangkok
}
# zones.each do |tzone|
#   spin do
#     time = get_time(tzone)
#     puts "Time in #{tzone}: #{time}"
#   end
# end

# suspend

def get_times(zones)
  Polyphony::Supervisor.new do |s|
    zones.each do |tzone|
      s.spin { [tzone, get_time(tzone)] }
    end
  end
end

get_times(zones).await.each do |tzone, time|
  puts "Time in #{tzone}: #{time}"
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
polyphony-0.45.0 examples/io/xx-httparty.rb
polyphony-0.44.0 examples/io/xx-httparty.rb
polyphony-0.43.11 examples/io/xx-httparty.rb
polyphony-0.43.10 examples/io/xx-httparty.rb
polyphony-0.43.9 examples/io/xx-httparty.rb
polyphony-0.43.8 examples/io/xx-httparty.rb
polyphony-0.43.6 examples/io/xx-httparty.rb
polyphony-0.43.5 examples/io/xx-httparty.rb
polyphony-0.43.4 examples/io/xx-httparty.rb
polyphony-0.43.3 examples/io/xx-httparty.rb
polyphony-0.43.2 examples/io/xx-httparty.rb
polyphony-0.43.1 examples/io/xx-httparty.rb
polyphony-0.43 examples/io/xx-httparty.rb
polyphony-0.42 examples/io/xx-httparty.rb
polyphony-0.41 examples/io/xx-httparty.rb
polyphony-0.40 examples/io/xx-httparty.rb
polyphony-0.39 examples/io/xx-httparty.rb
polyphony-0.38 examples/io/xx-httparty.rb
polyphony-0.36 examples/io/xx-httparty.rb
polyphony-0.34 examples/io/xx-httparty.rb