example/multi.rb in rest-more-1.0.2 vs example/multi.rb in rest-more-2.0.0

- old
+ new

@@ -1,28 +1,17 @@ require 'rest-more' -require 'eventmachine' -RestCore::EmHttpRequest # there might be a autoload bug? - # omitting this line would cause - # stack level too deep (SystemStackError) -RestCore::Builder.default_app = RestCore::Auto -facebook = RestCore::Facebook.new(:log_method => method(:puts)) +facebook = RC::Facebook.new(:log_method => method(:puts)) +puts "rest-client with threads doing concurrent requests" +a = [facebook.get('4'), facebook.get('5')] +puts "It's not blocking... but doing concurrent requests underneath" +p a.map{ |r| r['name'] } # here we want the values, so it blocks here +puts "DONE" -EM.run{ - Fiber.new{ - fiber = Fiber.current - result = {} - facebook.get('4'){ |response| - result[0] = response - fiber.resume(result) if result.size == 2 - } - puts "It's not blocking..." - facebook.get('4'){ |response| - result[1] = response - fiber.resume(result) if result.size == 2 - } - p Fiber.yield - EM.stop - }.resume - puts "It's not blocking..." +puts "callback also works" +facebook.get('6'){ |r| + p r['name'] } +puts "It's not blocking... but doing concurrent requests underneath" +facebook.wait # we block here to wait for the request done +puts "DONE"