fiber

Making multiple HTTP requests asynchronously

杀马特。学长 韩版系。学妹 提交于 2019-11-27 11:46:08
问题 require 'net/http' urls = [ {'link' => 'http://www.google.com/'}, {'link' => 'http://www.yandex.ru/'}, {'link' => 'http://www.baidu.com/'} ] urls.each do |u| u['content'] = Net::HTTP.get( URI.parse(u['link']) ) end print urls This code works in synchronous style. First request, second, third. I would like to send all requests asynchronously and print urls after all of them is done. What the best way to do it? Is Fiber suited for that? 回答1: Here's an example using threads. require 'net/http'

What is the difference between a thread and a fiber?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 04:58:53
问题 What is the difference between a thread and a fiber? I've heard of fibers from ruby and I've read heard they're available in other languages, could somebody explain to me in simple terms what is the difference between a thread and a fiber. 回答1: In the most simple terms, threads are generally considered to be preemptive (although this may not always be true, depending on the operating system) while fibers are considered to be light-weight, cooperative threads. Both are separate execution paths