Created
July 18, 2018 09:11
-
-
Save novikserg/d9417c7267dc36bf1c21e81687f9a633 to your computer and use it in GitHub Desktop.
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 "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