Skip to content

Commit 2710c43

Browse files
committed
Allow to disable auto termination of global executors
It was causing trouble when the gem was used in test-suites of other projects.
1 parent 3d20272 commit 2710c43

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/concurrent/configuration.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
161167
end

spec/concurrent/actor_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
module Concurrent
55
module Actor
6-
i_know_it_is_experimental!
76
AdHoc = Utils::AdHoc
87

98
# FIXME better tests!

0 commit comments

Comments
 (0)