Last active
April 3, 2023 11:31
-
-
Save v-kolesnikov/c5807aab0ac7ba5d1ba5e31be32e21e6 to your computer and use it in GitHub Desktop.
Asynchronous files downloader.
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
# frozen_string_literal: true | |
require 'down' | |
require 'dry/monads' | |
require 'dry/monads/result' | |
Down.backend :http | |
module DL | |
class Run | |
include Dry::Monads[:task] | |
attr_reader :urls | |
attr_reader :destination | |
def initialize(urls:, destination:) | |
@urls = urls | |
@destination = destination | |
end | |
def call | |
@urls.map do |url| | |
Task[:io] { Down.download(url, destination: destination) } | |
end.map(&:to_result) | |
end | |
end | |
end |
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
# frozen_string_literal: true | |
source "https://rubygems.org" | |
gem 'down' | |
gem 'dry-monads' | |
gem 'http' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment