Skip to content

Instantly share code, notes, and snippets.

@novikserg
Created July 18, 2018 09:11
Show Gist options
  • Save novikserg/d9417c7267dc36bf1c21e81687f9a633 to your computer and use it in GitHub Desktop.
Save novikserg/d9417c7267dc36bf1c21e81687f9a633 to your computer and use it in GitHub Desktop.
require "thwait"
class Job; end
module Processor
def self.perform(worker_count, jobs)
workers = worker_count.times.map do
Thread.new do
while job = jobs.pop
yield job
end
end
end
ThWait.all_waits(workers)
end
end
worker_count = 5
jobs = Array.new(10) { Job.new }
Processor.perform(worker_count, jobs) do |job|
puts job.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment