Skip to content

Instantly share code, notes, and snippets.

@manavid
Created August 22, 2017 23:03
Show Gist options
  • Save manavid/a577c8503df683087d98d3ebba5aeaf9 to your computer and use it in GitHub Desktop.
Save manavid/a577c8503df683087d98d3ebba5aeaf9 to your computer and use it in GitHub Desktop.
require 'concurrent'
pool = Concurrent::FixedThreadPool.new(8, idletime: nil)
100.times do |i|
pool.post do
rnd = SecureRandom.random_number(5)
puts "task #{i}: sleep #{rnd}"
sleep rnd
end
end
pool.shutdown
pool.wait_for_termination
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment