Skip to content

Instantly share code, notes, and snippets.

@edsu
Last active June 8, 2022 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edsu/c1fc69d3ae84382a4b2e9af37d040f1a to your computer and use it in GitHub Desktop.
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.
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