ruby - Making multiple HTTP requests asynchronously -


  की आवश्यकता होती है 'net / http' urls = [{{'link' => 'http://www.google .com / '}, {' link '=>' http://www.yandex.ru/ '}, {' link '=>' http://www.baidu.com/ '}] urls.each do | यू | यू ['सामग्री'] = नेट :: HTTP.get (URI.parse (यू ['लिंक'])) अंत प्रिंट यूआरएल  

यह कोड तुल्यकालिक शैली में काम करता है। पहला अनुरोध, दूसरा, तीसरा मैं सभी अनुरोधों को असिंक्रोनस भेजना चाहूंगा और उन सभी के बाद urls प्रिंट करना चाहूंगा।

यह करने का सबसे अच्छा तरीका क्या है? क्या उस के लिए फाइबर उपयुक्त है?

यहाँ धागे का उपयोग करते हुए एक उदाहरण है।

  'नेट / http' urls की आवश्यकता है [['' लिंक '= & gt; 'Http://www.google.com/'}, {'link' = & gt; 'Http://www.yandex.ru/'}, {'link' = & gt; 'Http://www.baidu.com/'}] urls.each do | u | Thread.new do u ['content'] = नेट :: HTTP.get (URI.parse (और ['link'])) "सफलतापूर्वक अनुरोध किया # यू ['लिंक']}" अगर urls.all? {| यू | U.has_key? ("Content")} "सभी यूआरएल प्राप्त की है!" निकास अंत अंत अंत सो  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -