1
1
require 'concurrent/dereferenceable'
2
2
require 'concurrent/observable'
3
- require 'concurrent/atomic/atomic_fixnum '
3
+ require 'concurrent/atomic/atomic_boolean '
4
4
require 'concurrent/executor/executor'
5
5
require 'concurrent/executor/safe_task_executor'
6
6
@@ -193,7 +193,7 @@ def initialize(opts = {}, &task)
193
193
self . timeout_interval = opts [ :timeout ] || opts [ :timeout_interval ] || TIMEOUT_INTERVAL
194
194
@run_now = opts [ :now ] || opts [ :run_now ]
195
195
@executor = Concurrent ::SafeTaskExecutor . new ( task )
196
- @running = Concurrent ::AtomicFixnum . new ( 0 )
196
+ @running = Concurrent ::AtomicBoolean . new ( false )
197
197
198
198
self . observers = CopyOnWriteObserverSet . new
199
199
end
@@ -202,7 +202,7 @@ def initialize(opts = {}, &task)
202
202
#
203
203
# @return [Boolean] `true` when running, `false` when shutting down or shutdown
204
204
def running?
205
- @running . value == 1
205
+ @running . true?
206
206
end
207
207
208
208
# Execute a previously created `TimerTask`.
@@ -222,8 +222,8 @@ def running?
222
222
# @since 0.6.0
223
223
def execute
224
224
mutex . synchronize do
225
- if @running . value == 0
226
- @running . value = 1
225
+ if @running . false?
226
+ @running . make_true
227
227
schedule_next_task ( @run_now ? 0 : @execution_interval )
228
228
end
229
229
end
@@ -299,7 +299,7 @@ def self.run!(*args, &block)
299
299
300
300
# @deprecated Updated to use `Executor` instead of `Runnable`
301
301
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?
303
303
self . execute
304
304
self . wait_for_termination
305
305
true
@@ -311,13 +311,13 @@ def run
311
311
312
312
# @!visibility private
313
313
def shutdown_execution
314
- @running . value = 0
314
+ @running . make_false
315
315
super
316
316
end
317
317
318
318
# @!visibility private
319
319
def kill_execution
320
- @running . value = 0
320
+ @running . make_false
321
321
super
322
322
end
323
323
@@ -328,7 +328,7 @@ def schedule_next_task(interval = execution_interval)
328
328
329
329
# @!visibility private
330
330
def execute_task ( completion )
331
- return unless @running . value == 1
331
+ return unless @running . true?
332
332
Concurrent ::timer ( timeout_interval , completion , &method ( :timeout_task ) )
333
333
success , value , reason = @executor . execute ( self )
334
334
if completion . try?
@@ -343,7 +343,7 @@ def execute_task(completion)
343
343
344
344
# @!visibility private
345
345
def timeout_task ( completion )
346
- return unless @running . value == 1
346
+ return unless @running . true?
347
347
if completion . try?
348
348
self . value = value
349
349
schedule_next_task
0 commit comments