Skip to content
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

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

Merged
merged 1 commit into from
Jul 5, 2023

Conversation

bensheldon
Copy link
Contributor

Also fixes some small other oddities I found when running the code example.

Closes #794

Also fixes some small other oddities I found when running the code example
@ioquatix ioquatix merged commit 483dd33 into ruby-concurrency:master Jul 5, 2023
# #=> 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>

@ioquatix
Copy link
Contributor

ioquatix commented Jul 5, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TimerTask#execute is not a blocking call
2 participants