-
-
Save jtoy/1174121 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'em-http' | |
EM.run do | |
def dispatch(opts) | |
opts | |
puts opts | |
h = EM::HttpRequest.new(opts[:uri]).get | |
h.callback { |rep| opts[:cb].call(rep) if opts[:cb] } | |
h.errback do |rep| | |
#how do i write this code in errback if I am passing my own errback handling code from the initial dispatch | |
opts[:retries] < 3 ? dispatch(opts.merge({:retries =>(opts[:retries] +1)})) : opts[:eb].call(rep) | |
end | |
end | |
cb = Proc.new{ |rep| [:success, rep.response]; EM.stop } | |
eb = Proc.new{ |rep| puts "original errback" ; EM.stop} | |
dispatch(:uri => 'http://badhos1212.com/',:cb => cb,:eb => eb,:retries => 0) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'em-http' | |
EM.run do | |
def dispatch(uri, retries = 0) | |
h = EM::HttpRequest.new(uri).get | |
h.callback { |rep| [:success, rep.response]; EM.stop } | |
h.errback do |rep| | |
p [:fail, rep] | |
retries < 3 ? dispatch(uri, retries+1) : EM.stop | |
end | |
end | |
dispatch('http://badhos1212.com/') | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'em-http' | |
EM.run do | |
def dispatch(uri, retries = 0) | |
h = EM::HttpRequest.new(uri).get | |
h.callback { |rep| [:success, rep.response]; EM.stop } | |
h.errback do |rep| | |
p [:fail, rep] | |
retries < 3 ? dispatch(uri, retries+1) : EM.stop | |
end | |
end | |
dispatch('http://badhos1212.com/') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment