Skip to content

Fix TimerTask docs to not refer to #execute as "blocking" #996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/concurrent-ruby/concurrent/timer_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module Concurrent
#
# @example Controlling execution from within the block
# timer_task = Concurrent::TimerTask.new(execution_interval: 1) do |task|
# task.execution_interval.times{ print 'Boom! ' }
# task.execution_interval.to_i.times{ print 'Boom! ' }
# print "\n"
# task.execution_interval += 1
# if task.execution_interval > 5
Expand All @@ -96,12 +96,11 @@ module Concurrent
# end
# end
#
# timer_task.execute # blocking call - this task will stop itself
# timer_task.execute
# #=> Boom!
# #=> Boom! Boom!
# #=> Boom! Boom! Boom!
# #=> Boom! Boom! Boom! Boom!
# #=> Boom! Boom! Boom! Boom! Boom!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you double check this removal is correct?

When I ran the code, I got:

Boom! 
Boom! Boom! 
Boom! Boom! Boom! 
Boom! Boom! Boom! Boom! 
Boom! Boom! Boom! Boom! Boom! 
Stopping...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry about that. I just re-ran it myself and also got 5 booms. I'll make a correction 🤦🏻

❯ bundle exec irb
Ignoring concurrent-ruby-ext-1.2.2 because its extensions are not built. Try: gem pristine concurrent-ruby-ext --version 1.2.2
irb(main):001:0> require 'concurrent/timer_task'
=> true
irb(main):002:1*     timer_task = Concurrent::TimerTask.new(execution_interval: 1) do |task|
irb(main):003:1*       task.execution_interval.to_i.times{ print 'Boom! ' }
irb(main):004:1*       print "\n"
irb(main):005:1*       task.execution_interval += 1
irb(main):006:2*       if task.execution_interval > 5
irb(main):007:2*         puts 'Stopping...'
irb(main):008:2*         task.shutdown
irb(main):009:1*       end
irb(main):010:0>     end
=>
#<Concurrent::TimerTask:0x0000000105b49d48
...
irb(main):011:0>
irb(main):012:0>     timer_task.execute
=>
#<Concurrent::TimerTask:0x0000000105b49d48
 @StopEvent=
  #<Concurrent::Event:0x0000000105b49ca8
   @__Condition__=#<Thread::ConditionVariable:0x00000001058d1160>,
   @__Lock__=#<Thread::Mutex:0x00000001058d1188>,
   @iteration=0,
   @set=false>,
 @StoppedEvent=
  #<Concurrent::Event:0x0000000105b49c58
   @__Condition__=#<Thread::ConditionVariable:0x00000001058d10c0>,
   @__Lock__=#<Thread::Mutex:0x00000001058d10e8>,
   @iteration=0,
   @set=false>,
 @__Condition__=#<Thread::ConditionVariable:0x00000001058d2178>,
 @__Lock__=#<Thread::Mutex:0x00000001058d21a0>,
 @auto_terminate=true,
 @copy_on_deref=nil,
 @do_nothing_on_deref=true,
 @dup_on_deref=nil,
 @execution_interval=1.0,
 @executor=
  #<Concurrent::SafeTaskExecutor:0x0000000105b49cf8
   @__Condition__=#<Thread::ConditionVariable:0x00000001058d1958>,
   @__Lock__=#<Thread::Mutex:0x00000001058d1980>,
   @exception_class=StandardError,
   @task=#<Proc:0x00000001058d1ef8 (irb):2>>,
 @freeze_on_deref=nil,
 @observers=
  #<Concurrent::Collection::CopyOnNotifyObserverSet:0x00000001058d14d0
   @__Condition__=#<Thread::ConditionVariable:0x00000001058d1340>,
   @__Lock__=#<Thread::Mutex:0x00000001058d1368>,
   @observers={}>,
 @run_now=nil,
 @running=#<Concurrent::AtomicBoolean:0x00000001058d1638 value:true>,
 @value=nil>
irb(main):013:0> Boom!
Boom! Boom!
Boom! Boom! Boom!
Boom! Boom! Boom! Boom!
Boom! Boom! Boom! Boom! Boom!
Stopping...
irb(main):013:0>

# #=> Stopping...
#
# @example Observation
Expand Down