Skip to content

Commit 245d0d2

Browse files
committed
Updated TimerTask ti use an AtomicBoolean rather than an AtomicFixnum.
1 parent b3657d7 commit 245d0d2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lib/concurrent/timer_task.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'concurrent/dereferenceable'
22
require 'concurrent/observable'
3-
require 'concurrent/atomic/atomic_fixnum'
3+
require 'concurrent/atomic/atomic_boolean'
44
require 'concurrent/executor/executor'
55
require 'concurrent/executor/safe_task_executor'
66

@@ -193,7 +193,7 @@ def initialize(opts = {}, &task)
193193
self.timeout_interval = opts[:timeout] || opts[:timeout_interval] || TIMEOUT_INTERVAL
194194
@run_now = opts[:now] || opts[:run_now]
195195
@executor = Concurrent::SafeTaskExecutor.new(task)
196-
@running = Concurrent::AtomicFixnum.new(0)
196+
@running = Concurrent::AtomicBoolean.new(false)
197197

198198
self.observers = CopyOnWriteObserverSet.new
199199
end
@@ -202,7 +202,7 @@ def initialize(opts = {}, &task)
202202
#
203203
# @return [Boolean] `true` when running, `false` when shutting down or shutdown
204204
def running?
205-
@running.value == 1
205+
@running.true?
206206
end
207207

208208
# Execute a previously created `TimerTask`.
@@ -222,8 +222,8 @@ def running?
222222
# @since 0.6.0
223223
def execute
224224
mutex.synchronize do
225-
if @running.value == 0
226-
@running.value = 1
225+
if @running.false?
226+
@running.make_true
227227
schedule_next_task(@run_now ? 0 : @execution_interval)
228228
end
229229
end
@@ -299,7 +299,7 @@ def self.run!(*args, &block)
299299

300300
# @deprecated Updated to use `Executor` instead of `Runnable`
301301
def run
302-
raise Concurrent::Runnable::LifecycleError.new('already running') if @running.value == 1
302+
raise Concurrent::Runnable::LifecycleError.new('already running') if @running.true?
303303
self.execute
304304
self.wait_for_termination
305305
true
@@ -311,13 +311,13 @@ def run
311311

312312
# @!visibility private
313313
def shutdown_execution
314-
@running.value = 0
314+
@running.make_false
315315
super
316316
end
317317

318318
# @!visibility private
319319
def kill_execution
320-
@running.value = 0
320+
@running.make_false
321321
super
322322
end
323323

@@ -328,7 +328,7 @@ def schedule_next_task(interval = execution_interval)
328328

329329
# @!visibility private
330330
def execute_task(completion)
331-
return unless @running.value == 1
331+
return unless @running.true?
332332
Concurrent::timer(timeout_interval, completion, &method(:timeout_task))
333333
success, value, reason = @executor.execute(self)
334334
if completion.try?
@@ -343,7 +343,7 @@ def execute_task(completion)
343343

344344
# @!visibility private
345345
def timeout_task(completion)
346-
return unless @running.value == 1
346+
return unless @running.true?
347347
if completion.try?
348348
self.value = value
349349
schedule_next_task

0 commit comments

Comments
 (0)