Created
November 27, 2011 21:04
-
-
Save sandal-china/1398151 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
class DownloadManager | |
def initialize | |
@downloads = [] | |
end | |
def save(url, filename) | |
downloads << Lazy.future { File.binwrite(filename, open(url).read) } | |
end | |
def finish_all_downloads | |
downloads.each { |d| Lazy.demand(d) } | |
end | |
private | |
attr_reader :downloads | |
end | |
downloader = DownloadManager.new | |
downloader.save("http://prawn.majesticseacreature.com/manual.pdf", "manual.pdf") | |
puts "Hey now, that was fast!" | |
downloader.save("http://sandal.github.com/rbp-book/pdfs/rbp_1-0.pdf", "rbp_1-0.pdf") | |
puts "So was that!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment