Skip to content

Instantly share code, notes, and snippets.

/threads.rb Secret

Created May 26, 2016 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6e9afcc2d3f75cf0874535f27485f1d2 to your computer and use it in GitHub Desktop.
Save anonymous/6e9afcc2d3f75cf0874535f27485f1d2 to your computer and use it in GitHub Desktop.
require 'httparty'
class API
def initialize
@endpoints = ['http://cnn.com', 'http://fox.com']
end
def process
step_1
end
def step_1
puts "Start step 1 \n"
threads = []
@endpoints.each {|endpoint| threads << Thread.new {get_request(endpoint)}}
threads.each {|thread| thread.join }
step_2
end
def step_2
puts "Start step 2 \n"
sleep(1)
puts "Finishing work in step 2 \n"
step_3
end
def step_3
puts "Start step 3 \n"
puts "Finishing work in step 3 \n"
end
def get_request(endpoint)
puts HTTParty.get(endpoint)
end
end
my_api = API.new()
my_api.process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment