Sha256: 4ce19cbc956b75102d5a3cb108922693db05ca5d0e1153a7b54885adbd1fd703

Contents?: true

Size: 598 Bytes

Versions: 90

Compression:

Stored size: 598 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
}

def get_times(zones)
  fibers = zones.map do |tzone|
    spin { [tzone, get_time(tzone)] }
  end
  Fiber.await(*fibers)
end

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

Version data entries

90 entries across 90 versions & 1 rubygems

Version Path
polyphony-1.6 examples/io/httparty.rb
polyphony-1.5 examples/io/httparty.rb
polyphony-1.4 examples/io/httparty.rb
polyphony-1.3 examples/io/httparty.rb
polyphony-1.2.1 examples/io/httparty.rb
polyphony-1.2 examples/io/httparty.rb
polyphony-1.1.1 examples/io/httparty.rb
polyphony-1.1 examples/io/httparty.rb
polyphony-1.0.2 examples/io/httparty.rb
polyphony-1.0.1 examples/io/httparty.rb
polyphony-1.0 examples/io/httparty.rb
polyphony-0.99.6 examples/io/httparty.rb
polyphony-0.99.5 examples/io/httparty.rb
polyphony-0.99.4 examples/io/httparty.rb
polyphony-0.99.3 examples/io/httparty.rb
polyphony-0.99.2 examples/io/httparty.rb
polyphony-0.99.1 examples/io/httparty.rb
polyphony-0.99 examples/io/httparty.rb
polyphony-0.98 examples/io/httparty.rb
polyphony-0.97 examples/io/httparty.rb