@@ -48,11 +48,9 @@ def initialize(opts = {})
48
48
def post ( delay , *args , &task )
49
49
raise ArgumentError . new ( 'no block given' ) unless block_given?
50
50
return false unless running?
51
- opts = {
52
- executor : @task_executor ,
53
- args : args ,
54
- timer_set : self
55
- }
51
+ opts = { executor : @task_executor ,
52
+ args : args ,
53
+ timer_set : self }
56
54
task = ScheduledTask . execute ( delay , opts , &task ) # may raise exception
57
55
task . unscheduled? ? false : task
58
56
end
@@ -74,11 +72,11 @@ def kill
74
72
# @param [Hash] opts the options to create the object with.
75
73
# @!visibility private
76
74
def ns_initialize ( opts )
77
- @queue = Collection ::NonConcurrentPriorityQueue . new ( order : :min )
78
- @task_executor = Options . executor_from_options ( opts ) || Concurrent . global_io_executor
79
- @timer_executor = SingleThreadExecutor . new
80
- @condition = Event . new
81
- @ruby_pid = $$ # detects if Ruby has forked
75
+ @queue = Collection ::NonConcurrentPriorityQueue . new ( order : :min )
76
+ @task_executor = Options . executor_from_options ( opts ) || Concurrent . global_io_executor
77
+ @timer_executor = SingleThreadExecutor . new
78
+ @condition = Event . new
79
+ @ruby_pid = $$ # detects if Ruby has forked
82
80
self . auto_terminate = opts . fetch ( :auto_terminate , true )
83
81
end
84
82
@@ -90,15 +88,15 @@ def ns_initialize(opts)
90
88
#
91
89
# @!visibility private
92
90
def post_task ( task )
93
- synchronize { ns_post_task ( task ) }
91
+ synchronize { ns_post_task ( task ) }
94
92
end
95
93
96
94
# @!visibility private
97
95
def ns_post_task ( task )
98
96
return false unless ns_running?
99
97
ns_reset_if_forked
100
98
if ( task . initial_delay ) <= 0.01
101
- task . executor . post { task . process_task }
99
+ task . executor . post { task . process_task }
102
100
else
103
101
@queue . push ( task )
104
102
# only post the process method when the queue is empty
@@ -116,7 +114,7 @@ def ns_post_task(task)
116
114
#
117
115
# @!visibility private
118
116
def remove_task ( task )
119
- synchronize { @queue . delete ( task ) }
117
+ synchronize { @queue . delete ( task ) }
120
118
end
121
119
122
120
# `ExecutorService` callback called during shutdown.
@@ -148,7 +146,7 @@ def process_tasks
148
146
task = synchronize { @condition . reset ; @queue . peek }
149
147
break unless task
150
148
151
- now = Concurrent . monotonic_time
149
+ now = Concurrent . monotonic_time
152
150
diff = task . schedule_time - now
153
151
154
152
if diff <= 0
@@ -165,7 +163,7 @@ def process_tasks
165
163
# queue now must have the same pop time, or a closer one, as
166
164
# when we peeked).
167
165
task = synchronize { @queue . pop }
168
- task . executor . post { task . process_task }
166
+ task . executor . post { task . process_task }
169
167
else
170
168
@condition . wait ( [ diff , 60 ] . min )
171
169
end
0 commit comments