7
7
8
8
module Concurrent
9
9
10
- # @api private
10
+ # @!macro [new] executor_service_method_post
11
+ #
12
+ # Submit a task to the executor for asynchronous processing.
13
+ #
14
+ # @param [Array] args zero or more arguments to be passed to the task
15
+ #
16
+ # @yield the asynchronous task to perform
17
+ #
18
+ # @return [Boolean] `true` if the task is queued, `false` if the executor
19
+ # is not running
20
+ #
21
+ # @raise [ArgumentError] if no task is given
22
+
23
+ # @!macro [new] executor_service_method_left_shift
24
+ #
25
+ # Submit a task to the executor for asynchronous processing.
26
+ #
27
+ # @param [Proc] task the asynchronous task to perform
28
+ #
29
+ # @return [self] returns itself
30
+
31
+ # @!macro [new] executor_service_method_can_overflow_question
32
+ #
33
+ # Does the task queue have a maximum size?
34
+ #
35
+ # @return [Boolean] True if the task queue has a maximum size else false.
36
+
37
+ # @!macro [new] executor_service_method_serialized_question
38
+ #
39
+ # Does this executor guarantee serialization of its operations?
40
+ #
41
+ # @return [Boolean] True if the executor guarantees that all operations
42
+ # will be post in the order they are received and no two operations may
43
+ # occur simultaneously. Else false.
44
+
45
+
46
+
47
+
48
+
49
+ # @!macro [new] executor_service_public_api
50
+ #
51
+ # @!method post(*args, &task)
52
+ # @!macro executor_service_method_post
53
+ #
54
+ # @!method <<(task)
55
+ # @!macro executor_service_method_left_shift
56
+ #
57
+ # @!method can_overflow?
58
+ # @!macro executor_service_method_can_overflow_question
59
+ #
60
+ # @!method serialized?
61
+ # @!macro executor_service_method_serialized_question
62
+
63
+
64
+
65
+
66
+
67
+ # @!macro executor_service_public_api
68
+ # @!visibility private
11
69
module ExecutorService
12
70
include Concern ::Logging
13
71
include Concern ::Deprecation
14
72
15
- # @!macro [attach] executor_service_method_post
16
- #
17
- # Submit a task to the executor for asynchronous processing.
18
- #
19
- # @param [Array] args zero or more arguments to be passed to the task
20
- #
21
- # @yield the asynchronous task to perform
22
- #
23
- # @return [Boolean] `true` if the task is queued, `false` if the executor
24
- # is not running
25
- #
26
- # @raise [ArgumentError] if no task is given
73
+ # @!macro executor_service_method_post
27
74
def post ( *args , &task )
28
75
raise NotImplementedError
29
76
end
30
77
31
- # @!macro [attach] executor_service_method_left_shift
32
- #
33
- # Submit a task to the executor for asynchronous processing.
34
- #
35
- # @param [Proc] task the asynchronous task to perform
36
- #
37
- # @return [self] returns itself
78
+ # @!macro executor_service_method_left_shift
38
79
def <<( task )
39
80
post ( &task )
40
81
self
41
82
end
42
83
43
- # @!macro [attach] executor_service_method_can_overflow_question
44
- #
45
- # Does the task queue have a maximum size?
46
- #
47
- # @return [Boolean] True if the task queue has a maximum size else false.
84
+ # @!macro executor_service_method_can_overflow_question
48
85
#
49
86
# @note Always returns `false`
50
87
def can_overflow?
51
88
false
52
89
end
53
90
54
- # @!macro [attach] executor_service_method_serialized_question
55
- #
56
- # Does this executor guarantee serialization of its operations?
57
- #
58
- # @return [Boolean] True if the executor guarantees that all operations
59
- # will be post in the order they are received and no two operations may
60
- # occur simultaneously. Else false.
91
+ # @!macro executor_service_method_serialized_question
61
92
#
62
93
# @note Always returns `false`
63
94
def serialized?
@@ -83,7 +114,7 @@ def serialized?
83
114
# foo.is_a? Concurrent::SerialExecutor #=> true
84
115
# foo.serialized? #=> true
85
116
#
86
- # @api private
117
+ # @!visibility private
87
118
module SerialExecutorService
88
119
include ExecutorService
89
120
@@ -95,6 +126,110 @@ def serialized?
95
126
end
96
127
end
97
128
129
+
130
+
131
+
132
+
133
+ # @!macro [new] executor_service_attr_reader_fallback_policy
134
+ # @return [Symbol] The fallback policy in effect. Either `:abort`, `:discard`, or `:caller_runs`.
135
+
136
+ # @!macro [new] executor_service_method_shutdown
137
+ #
138
+ # Begin an orderly shutdown. Tasks already in the queue will be executed,
139
+ # but no new tasks will be accepted. Has no additional effect if the
140
+ # thread pool is not running.
141
+
142
+ # @!macro [new] executor_service_method_kill
143
+ #
144
+ # Begin an immediate shutdown. In-progress tasks will be allowed to
145
+ # complete but enqueued tasks will be dismissed and no new tasks
146
+ # will be accepted. Has no additional effect if the thread pool is
147
+ # not running.
148
+
149
+ # @!macro [new] executor_service_method_wait_for_termination
150
+ #
151
+ # Block until executor shutdown is complete or until `timeout` seconds have
152
+ # passed.
153
+ #
154
+ # @note Does not initiate shutdown or termination. Either `shutdown` or `kill`
155
+ # must be called before this method (or on another thread).
156
+ #
157
+ # @param [Integer] timeout the maximum number of seconds to wait for shutdown to complete
158
+ #
159
+ # @return [Boolean] `true` if shutdown complete or false on `timeout`
160
+
161
+ # @!macro [new] executor_service_method_running_question
162
+ #
163
+ # Is the executor running?
164
+ #
165
+ # @return [Boolean] `true` when running, `false` when shutting down or shutdown
166
+
167
+ # @!macro [new] executor_service_method_shuttingdown_question
168
+ #
169
+ # Is the executor shuttingdown?
170
+ #
171
+ # @return [Boolean] `true` when not running and not shutdown, else `false`
172
+
173
+ # @!macro [new] executor_service_method_shutdown_question
174
+ #
175
+ # Is the executor shutdown?
176
+ #
177
+ # @return [Boolean] `true` when shutdown, `false` when shutting down or running
178
+
179
+ # @!macro [new] executor_service_method_auto_terminate_question
180
+ #
181
+ # Is the executor auto-terminate when the application exits?
182
+ #
183
+ # @return [Boolean] `true` when auto-termination is enabled else `false`.
184
+
185
+ # @!macro [new] executor_service_method_auto_terminate_setter
186
+ #
187
+ # Set the auto-terminate behavior for this executor.
188
+ #
189
+ # @param [Boolean] value The new auto-terminate value to set for this executor.
190
+ #
191
+ # @return [Boolean] `true` when auto-termination is enabled else `false`.
192
+
193
+
194
+
195
+
196
+
197
+ # @!macro [new] abstract_executor_service_public_api
198
+ #
199
+ # @!macro executor_service_public_api
200
+ #
201
+ # @!attribute [r] fallback_policy
202
+ # @!macro executor_service_attr_reader_fallback_policy
203
+ #
204
+ # @!method shutdown
205
+ # @!macro executor_service_method_shutdown
206
+ #
207
+ # @!method kill
208
+ # @!macro executor_service_method_kill
209
+ #
210
+ # @!method wait_for_termination(timeout = nil)
211
+ # @!macro executor_service_method_wait_for_termination
212
+ #
213
+ # @!method running?
214
+ # @!macro executor_service_method_running_question
215
+ #
216
+ # @!method shuttingdown?
217
+ # @!macro executor_service_method_shuttingdown_question
218
+ #
219
+ # @!method shutdown?
220
+ # @!macro executor_service_method_shutdown_question
221
+ #
222
+ # @!method auto_terminate?
223
+ # @!macro executor_service_method_auto_terminate_question
224
+ #
225
+ # @!method auto_terminate=(value)
226
+ # @!macro executor_service_method_auto_terminate_setter
227
+
228
+
229
+
230
+
231
+
232
+ # @!macro abstract_executor_service_public_api
98
233
# @!visibility private
99
234
class AbstractExecutorService < Synchronization ::Object
100
235
include ExecutorService
@@ -103,7 +238,6 @@ class AbstractExecutorService < Synchronization::Object
103
238
FALLBACK_POLICIES = [ :abort , :discard , :caller_runs ] . freeze
104
239
105
240
# @!macro [attach] executor_service_attr_reader_fallback_policy
106
- # @return [Symbol] The fallback policy in effect. Either `:abort`, `:discard`, or `:caller_runs`.
107
241
attr_reader :fallback_policy
108
242
109
243
# Create a new thread pool.
@@ -113,82 +247,41 @@ def initialize(*args, &block)
113
247
end
114
248
115
249
# @!macro [attach] executor_service_method_shutdown
116
- #
117
- # Begin an orderly shutdown. Tasks already in the queue will be executed,
118
- # but no new tasks will be accepted. Has no additional effect if the
119
- # thread pool is not running.
120
250
def shutdown
121
251
raise NotImplementedError
122
252
end
123
253
124
254
# @!macro [attach] executor_service_method_kill
125
- #
126
- # Begin an immediate shutdown. In-progress tasks will be allowed to
127
- # complete but enqueued tasks will be dismissed and no new tasks
128
- # will be accepted. Has no additional effect if the thread pool is
129
- # not running.
130
255
def kill
131
256
raise NotImplementedError
132
257
end
133
258
134
259
# @!macro [attach] executor_service_method_wait_for_termination
135
- #
136
- # Block until executor shutdown is complete or until `timeout` seconds have
137
- # passed.
138
- #
139
- # @note Does not initiate shutdown or termination. Either `shutdown` or `kill`
140
- # must be called before this method (or on another thread).
141
- #
142
- # @param [Integer] timeout the maximum number of seconds to wait for shutdown to complete
143
- #
144
- # @return [Boolean] `true` if shutdown complete or false on `timeout`
145
260
def wait_for_termination ( timeout = nil )
146
261
raise NotImplementedError
147
262
end
148
263
149
264
# @!macro [attach] executor_service_method_running_question
150
- #
151
- # Is the executor running?
152
- #
153
- # @return [Boolean] `true` when running, `false` when shutting down or shutdown
154
265
def running?
155
266
synchronize { ns_running? }
156
267
end
157
268
158
269
# @!macro [attach] executor_service_method_shuttingdown_question
159
- #
160
- # Is the executor shuttingdown?
161
- #
162
- # @return [Boolean] `true` when not running and not shutdown, else `false`
163
270
def shuttingdown?
164
271
synchronize { ns_shuttingdown? }
165
272
end
166
273
167
274
# @!macro [attach] executor_service_method_shutdown_question
168
- #
169
- # Is the executor shutdown?
170
- #
171
- # @return [Boolean] `true` when shutdown, `false` when shutting down or running
172
275
def shutdown?
173
276
synchronize { ns_shutdown? }
174
277
end
175
278
176
279
# @!macro [attach] executor_service_method_auto_terminate_question
177
- #
178
- # Is the executor auto-terminate when the application exits?
179
- #
180
- # @return [Boolean] `true` when auto-termination is enabled else `false`.
181
280
def auto_terminate?
182
281
synchronize { ns_auto_terminate? }
183
282
end
184
283
185
284
# @!macro [attach] executor_service_method_auto_terminate_setter
186
- #
187
- # Set the auto-terminate behavior for this executor.
188
- #
189
- # @param [Boolean] value The new auto-terminate value to set for this executor.
190
- #
191
- # @return [Boolean] `true` when auto-termination is enabled else `false`.
192
285
def auto_terminate = ( value )
193
286
synchronize { self . ns_auto_terminate = value }
194
287
end
@@ -265,7 +358,8 @@ def terminate_at_exit
265
358
end
266
359
end
267
360
268
- # @api private
361
+ # @!macro abstract_executor_service_public_api
362
+ # @!visibility private
269
363
class RubyExecutorService < AbstractExecutorService
270
364
271
365
def initialize ( *args , &block )
@@ -333,7 +427,8 @@ def ns_shutdown?
333
427
334
428
if Concurrent . on_jruby?
335
429
336
- # @api private
430
+ # @!macro abstract_executor_service_public_api
431
+ # @!visibility private
337
432
class JavaExecutorService < AbstractExecutorService
338
433
java_import 'java.lang.Runnable'
339
434
0 commit comments