Skip to content

Commit 23cec0a

Browse files
committed
inlined a couple of methods
1 parent 024edfb commit 23cec0a

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

lib/concurrent/executor/timer_set.rb

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,21 @@ def initialize(opts = {})
4343
# @raise [ArgumentError] if no block is given
4444
def post(intended_time, &task)
4545
time = TimerSet.calculate_schedule_time(intended_time).to_f
46-
if super(time, &task)
47-
check_processing_thread!
46+
raise ArgumentError.new('no block given') unless block_given?
47+
48+
mutex.synchronize do
49+
return false unless running?
50+
51+
if (time - Time.now.to_f) <= 0.01
52+
@executor.post(&task)
53+
else
54+
@queue.push(Task.new(time, task))
55+
check_processing_thread!
56+
end
57+
4858
true
4959
end
60+
5061
end
5162

5263
alias_method :kill, :shutdown
@@ -84,20 +95,12 @@ def self.calculate_schedule_time(intended_time, now = Time.now)
8495
# @!visibility private
8596
Task = Struct.new(:time, :op) do
8697
include Comparable
98+
8799
def <=>(other)
88100
self.time <=> other.time
89101
end
90102
end
91103

92-
# @!visibility private
93-
def execute(time, &task)
94-
if (time - Time.now.to_f) <= 0.01
95-
@executor.post(&task)
96-
else
97-
@queue.push(Task.new(time, task))
98-
end
99-
end
100-
101104
# @!visibility private
102105
def shutdown_execution
103106
@queue.clear
@@ -114,15 +117,13 @@ def shutdown_execution
114117
#
115118
# @!visibility private
116119
def check_processing_thread!
117-
mutex.synchronize do
118-
return if shutdown? || @queue.empty?
119-
if @thread && @thread.status == 'sleep'
120-
@thread.wakeup
121-
elsif @thread.nil? || ! @thread.alive?
122-
@thread = Thread.new do
123-
Thread.current.abort_on_exception = true
124-
process_tasks
125-
end
120+
return if shutdown? || @queue.empty?
121+
if @thread && @thread.status == 'sleep'
122+
@thread.wakeup
123+
elsif @thread.nil? || !@thread.alive?
124+
@thread = Thread.new do
125+
Thread.current.abort_on_exception = true
126+
process_tasks
126127
end
127128
end
128129
end

0 commit comments

Comments
 (0)