Skip to content

Instantly share code, notes, and snippets.

@stravid
Created January 10, 2018 18:46
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 stravid/f38627aaa065b0276e550787003fafb6 to your computer and use it in GitHub Desktop.
Save stravid/f38627aaa065b0276e550787003fafb6 to your computer and use it in GitHub Desktop.
require "rubygems"
require "bundler/setup"
require "concurrent"
tasks = 10.times.map do |s|
Concurrent::TimerTask.new(execution_interval: 1) do
sleep s
puts "s: #{s}\n"
end
end
begin
tasks.each { |t| t.execute }
sleep
rescue Interrupt
puts "Received INT"
puts "Shutting down tasks"
tasks.each { |t| t.shutdown }
ensure
puts "Releasing resources"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment