Created
April 9, 2013 15:57
-
-
Save JacobNinja/5346915 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| urls = ['http://www.google.com', 'http://www.github.com', 'http://www.twitter.com'] | |
| concurrent_url_grabber = Enumerator.new do |y| | |
| urls.map do |url| | |
| Thread.new do | |
| result = http_request(url) | |
| # Need a mutex here for multithreaded VMs | |
| y << result | |
| end | |
| end.each(&:join) | |
| end | |
| concurrent_url_grabbler.map(&:code) # => ['200', '200', '200'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jstorimer I had a different take on the difference between
Thread#valueandThread#join. I thought#valuecalls#joininternally and returns a value, while#joinreturns the instance of the new Thread? Is that not correct? If it is I do not see how there is no need for mutex at first glance.