Closed
Description
Hi,
I was looking through the TimerTask examples and noticed that the one below isn't working as documented:
# timer_task_boom_test.rb
# from https://github.com/ruby-concurrency/concurrent-ruby/blob/master/lib/concurrent/timer_task.rb#L94-L111
timer_task = Concurrent::TimerTask.new(execution_interval: 1) do |task|
task.execution_interval.to_i.times { print 'Boom! ' }
print "\n"
task.execution_interval += 1
if task.execution_interval > 5
puts 'Stopping...'
task.shutdown
end
end
timer_task.execute # blocking call - this task will stop itself
#=> Boom!
#=> Boom! Boom!
#=> Boom! Boom! Boom!
#=> Boom! Boom! Boom! Boom!
#=> Boom! Boom! Boom! Boom! Boom!
#=> Stopping...
If I put those contents into a file and run it via ruby timer_task_boom_test.rb
, it exits immediately. If I add a sleep
right after the timer_task.execute line then I see the Boom!
s printed out.
Is timer_task.execute supposed to be a blocking call? Or has the behavior changed and this example is no longer valid?
more info
* Operating system: mac
* Ruby implementation: Ruby 2.2.3
* `concurrent-ruby` version: 1.1.4
* `concurrent-ruby-ext` installed: no
* `concurrent-ruby-edge` used: no