Last active
June 8, 2022 14:42
-
-
Save edsu/c1fc69d3ae84382a4b2e9af37d040f1a to your computer and use it in GitHub Desktop.
An example of using an enumerable with parallel, but which gets flattened into a list by parallel prior to processing.
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
require 'pathname' | |
require 'parallel' | |
# a directory to traverse | |
dir = ARGV[0] | |
# files is an Enumerator | |
files = Pathname.new(dir).find | |
results = Parallel.map(files, processes: 3) do |f| | |
# some expensive operation here | |
puts f | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment