@@ -17,13 +17,17 @@ class Configuration
17
17
# lambda { |level, progname, message = nil, &block| _ }
18
18
attr_accessor :logger
19
19
20
+ # defines if executors should be auto-terminated in at_exit callback
21
+ attr_accessor :auto_terminate
22
+
20
23
# Create a new configuration object.
21
24
def initialize
22
25
immediate_executor = ImmediateExecutor . new
23
26
@global_task_pool = Delay . new ( executor : immediate_executor ) { new_task_pool }
24
27
@global_operation_pool = Delay . new ( executor : immediate_executor ) { new_operation_pool }
25
28
@global_timer_set = Delay . new ( executor : immediate_executor ) { Concurrent ::TimerSet . new }
26
29
@logger = no_logger
30
+ @auto_terminate = true
27
31
end
28
32
29
33
# if assigned to {#logger}, it will log nothing.
@@ -129,6 +133,12 @@ def self.configure
129
133
yield ( configuration )
130
134
end
131
135
136
+ def self . finalize_global_executors
137
+ self . finalize_executor ( self . configuration . global_timer_set )
138
+ self . finalize_executor ( self . configuration . global_task_pool )
139
+ self . finalize_executor ( self . configuration . global_operation_pool )
140
+ end
141
+
132
142
private
133
143
134
144
# Attempt to properly shutdown the given executor using the `shutdown` or
@@ -150,12 +160,8 @@ def self.finalize_executor(executor)
150
160
false
151
161
end
152
162
153
-
154
163
# set exit hook to shutdown global thread pools
155
164
at_exit do
156
- self . finalize_executor ( self . configuration . global_timer_set )
157
- self . finalize_executor ( self . configuration . global_task_pool )
158
- self . finalize_executor ( self . configuration . global_operation_pool )
159
- # TODO may break other test suites using concurrent-ruby, terminates before test is run
165
+ finalize_global_executors if configuration . auto_terminate
160
166
end
161
167
end
0 commit comments