@@ -17,13 +17,17 @@ class Configuration
1717 # lambda { |level, progname, message = nil, &block| _ }
1818 attr_accessor :logger
1919
20+ # defines if executors should be auto-terminated in at_exit callback
21+ attr_accessor :auto_terminate
22+
2023 # Create a new configuration object.
2124 def initialize
2225 immediate_executor = ImmediateExecutor . new
2326 @global_task_pool = Delay . new ( executor : immediate_executor ) { new_task_pool }
2427 @global_operation_pool = Delay . new ( executor : immediate_executor ) { new_operation_pool }
2528 @global_timer_set = Delay . new ( executor : immediate_executor ) { Concurrent ::TimerSet . new }
2629 @logger = no_logger
30+ @auto_terminate = true
2731 end
2832
2933 # if assigned to {#logger}, it will log nothing.
@@ -129,6 +133,12 @@ def self.configure
129133 yield ( configuration )
130134 end
131135
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+
132142 private
133143
134144 # Attempt to properly shutdown the given executor using the `shutdown` or
@@ -150,12 +160,8 @@ def self.finalize_executor(executor)
150160 false
151161 end
152162
153-
154163 # set exit hook to shutdown global thread pools
155164 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
160166 end
161167end
0 commit comments