Skip to content

Commit

Permalink
Use concurrent-ruby's new Promises API
Browse files Browse the repository at this point in the history
  • Loading branch information
olivier-thatch committed Feb 2, 2024
1 parent 5b040f3 commit 1d3a8d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions lib/sprockets/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ def find(*args, &block)
return to_enum(__method__, *args) unless block_given?

environment = self.environment.cached
promises = args.flatten.map do |path|
Concurrent::Promise.execute(executor: executor) do
futures = args.flatten.map do |path|
Concurrent::Promises.future_on(executor) do
environment.find_all_linked_assets(path).to_a
end
end

promises.each do |promise|
promise.value!.each(&block)
futures.each do |future|
future.value!.each(&block)
end

nil
Expand Down Expand Up @@ -188,15 +188,15 @@ def compile(*args)

filenames << asset.filename

promise = nil
future = nil
exporters_for_asset(asset) do |exporter|
next if exporter.skip?(logger)

if promise.nil?
promise = Concurrent::Promise.new(executor: executor) { exporter.call }
concurrent_exporters << promise.execute
if future.nil?
future = Concurrent::Promises.future_on(executor) { exporter.call }
concurrent_exporters << future
else
concurrent_exporters << promise.then { exporter.call }
concurrent_exporters << future.then { exporter.call }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion sprockets.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.executables = ["sprockets"]

s.add_dependency "rack", ">= 2.2.4", "< 4"
s.add_dependency "concurrent-ruby", "~> 1.0"
s.add_dependency "concurrent-ruby", "~> 1.1"

s.add_development_dependency "m", ">= 0"
s.add_development_dependency "babel-transpiler", "~> 0.6"
Expand Down

0 comments on commit 1d3a8d1

Please sign in to comment.