File tree Expand file tree Collapse file tree 4 files changed +42
-42
lines changed Expand file tree Collapse file tree 4 files changed +42
-42
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,16 @@ def shutdown?
51
51
stop_event . set?
52
52
end
53
53
54
+ # Begin an orderly shutdown. Tasks already in the queue will be executed,
55
+ # but no new tasks will be accepted. Has no additional effect if the
56
+ # thread pool is not running.
54
57
def shutdown
58
+ mutex . synchronize do
59
+ return unless running?
60
+ stop_event . set
61
+ stop_execution
62
+ end
63
+ true
55
64
end
56
65
57
66
def kill
@@ -83,6 +92,10 @@ def init_executor
83
92
def execute ( *args , &task )
84
93
raise NotImplementedError
85
94
end
95
+
96
+ def stop_execution
97
+ stopped_event . set
98
+ end
86
99
end
87
100
88
101
if RUBY_PLATFORM == 'java'
Original file line number Diff line number Diff line change @@ -17,18 +17,6 @@ def initialize(opts = {})
17
17
init_executor
18
18
end
19
19
20
- # Begin an orderly shutdown. Tasks already in the queue will be executed,
21
- # but no new tasks will be accepted. Has no additional effect if the
22
- # thread pool is not running.
23
- def shutdown
24
- mutex . synchronize do
25
- return unless running?
26
- stop_event . set
27
- @queue << :stop
28
- stopped_event . set unless alive?
29
- end
30
- end
31
-
32
20
# Begin an immediate shutdown. In-progress tasks will be allowed to
33
21
# complete but enqueued tasks will be dismissed and no new tasks
34
22
# will be accepted. Has no additional effect if the thread pool is
@@ -46,26 +34,37 @@ def kill
46
34
47
35
protected
48
36
37
+ # @!visibility private
49
38
def execute ( *args , &task )
50
39
supervise
51
40
@queue << [ args , task ]
52
41
end
53
42
43
+ # @!visibility private
44
+ def stop_execution
45
+ @queue << :stop
46
+ stopped_event . set unless alive?
47
+ end
48
+
49
+ # @!visibility private
54
50
def alive?
55
51
@thread && @thread . alive?
56
52
end
57
53
54
+ # @!visibility private
58
55
def supervise
59
56
@thread = new_worker_thread unless alive?
60
57
end
61
58
59
+ # @!visibility private
62
60
def new_worker_thread
63
61
Thread . new do
64
62
Thread . current . abort_on_exception = false
65
63
work
66
64
end
67
65
end
68
66
67
+ # @!visibility private
69
68
def work
70
69
loop do
71
70
task = @queue . pop
Original file line number Diff line number Diff line change @@ -132,23 +132,6 @@ def status
132
132
mutex . synchronize { @pool . collect { |worker | worker . status } }
133
133
end
134
134
135
- # Begin an orderly shutdown. Tasks already in the queue will be executed,
136
- # but no new tasks will be accepted. Has no additional effect if the
137
- # thread pool is not running.
138
- def shutdown
139
- mutex . synchronize do
140
- break unless running?
141
- @queue . clear
142
- stop_event . set
143
- if @pool . empty?
144
- stopped_event . set
145
- else
146
- @pool . length . times { @queue << :stop }
147
- end
148
- end
149
- true
150
- end
151
-
152
135
# Begin an immediate shutdown. In-progress tasks will be allowed to
153
136
# complete but enqueued tasks will be dismissed and no new tasks
154
137
# will be accepted. Has no additional effect if the thread pool is
@@ -200,6 +183,16 @@ def execute(*args, &task)
200
183
grow_pool
201
184
end
202
185
186
+ # @!visibility private
187
+ def stop_execution
188
+ @queue . clear
189
+ if @pool . empty?
190
+ stopped_event . set
191
+ else
192
+ @pool . length . times { @queue << :stop }
193
+ end
194
+ end
195
+
203
196
# Handler which executes the `overflow_policy` once the queue size
204
197
# reaches `max_queue`.
205
198
#
Original file line number Diff line number Diff line change @@ -49,19 +49,6 @@ def post(intended_time, &task)
49
49
end
50
50
end
51
51
52
- # Begin an orderly shutdown. Tasks already in the queue will be executed,
53
- # but no new tasks will be accepted. Has no additional effect if the
54
- # thread pool is not running.
55
- def shutdown
56
- mutex . synchronize do
57
- break unless running?
58
- stop_event . set
59
- @queue . clear
60
- @thread . kill if @thread
61
- stopped_event . set
62
- end
63
- true
64
- end
65
52
alias_method :kill , :shutdown
66
53
67
54
# Calculate an Epoch time with milliseconds at which to execute a
@@ -102,6 +89,7 @@ def <=>(other)
102
89
end
103
90
end
104
91
92
+ # @!visibility private
105
93
def execute ( time , &task )
106
94
if ( time - Time . now . to_f ) <= 0.01
107
95
@executor . post ( &task )
@@ -110,6 +98,13 @@ def execute(time, &task)
110
98
end
111
99
end
112
100
101
+ # @!visibility private
102
+ def stop_execution
103
+ @queue . clear
104
+ @thread . kill if @thread
105
+ stopped_event . set
106
+ end
107
+
113
108
# Check the status of the processing thread. This thread is responsible
114
109
# for monitoring the internal task queue and sending tasks to the
115
110
# executor when it is time for them to be processed. If there is no
You can’t perform that action at this time.
0 commit comments