Skip to content

Instantly share code, notes, and snippets.

@v-kolesnikov v-kolesnikov/Gemfile

Last active Apr 21, 2020
Embed
What would you like to do?
Asynchronous files downloader.
# 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
# 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
You can’t perform that action at this time.