Skip to content

Instantly share code, notes, and snippets.

@matthewd
Created January 22, 2016 21:10
Show Gist options
  • Save matthewd/bdc60893cc980e0afc01 to your computer and use it in GitHub Desktop.
Save matthewd/bdc60893cc980e0afc01 to your computer and use it in GitHub Desktop.
diff --git a/lib/sprockets/manifest.rb b/lib/sprockets/manifest.rb
index e514ebb..9797575 100644
--- a/lib/sprockets/manifest.rb
+++ b/lib/sprockets/manifest.rb
@@ -165,6 +165,8 @@ def compile(*args)
concurrent_compressors = []
concurrent_writers = []
+ pool = Concurrent::FixedThreadPool.new(5)
+
find(*args) do |asset|
files[asset.digest_path] = {
'logical_path' => asset.logical_path,
@@ -189,7 +191,7 @@ def compile(*args)
logger.debug "Skipping #{target}, already exists"
else
logger.info "Writing #{target}"
- write_file = Concurrent::Future.execute { asset.write_to target }
+ write_file = Concurrent::Future.execute(executor: pool) { asset.write_to target }
concurrent_writers << write_file
end
filenames << asset.filename
@@ -202,15 +204,17 @@ def compile(*args)
logger.debug "Skipping #{target}.gz, already exists"
else
logger.info "Writing #{target}.gz"
- concurrent_compressors << Concurrent::Future.execute do
+ concurrent_compressors << Concurrent::Future.execute(executor: pool) do
write_file.wait! if write_file
gzip.compress(target)
end
end
end
+
concurrent_writers.each(&:wait!)
concurrent_compressors.each(&:wait!)
+ pool.shutdown
save
filenames
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment