Skip to content

Instantly share code, notes, and snippets.

@wycleffsean
Created August 20, 2019 22:36
Show Gist options
  • Select an option

  • Save wycleffsean/4140718d4c7cd2a2fc513a00fd9dfd15 to your computer and use it in GitHub Desktop.

Select an option

Save wycleffsean/4140718d4c7cd2a2fc513a00fd9dfd15 to your computer and use it in GitHub Desktop.
Peach
class Peach
private_class_method :new
def self.enum_for(*args)
new(*args)
end
def initialize(list, pool_size = 5)
@queue = list.inject(Queue.new, :<<)
@pool_size = pool_size
end
def each
Array.new(@pool_size) do
Thread.new do
yield(@queue.pop, @queue) until @queue.empty?
end
end.each(&:join)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment