File tree Expand file tree Collapse file tree 3 files changed +21
-17
lines changed
lib/concurrent-ruby/concurrent/executor Expand file tree Collapse file tree 3 files changed +21
-17
lines changed Original file line number Diff line number Diff line change @@ -81,5 +81,21 @@ def run
81
81
end
82
82
private_constant :Job
83
83
end
84
+
85
+ class DaemonThreadFactory
86
+ # hide include from YARD
87
+ send :include , java . util . concurrent . ThreadFactory
88
+
89
+ def initialize ( daemonize = true )
90
+ @daemonize = daemonize
91
+ end
92
+
93
+ def newThread ( runnable )
94
+ thread = java . util . concurrent . Executors . defaultThreadFactory ( ) . newThread ( runnable )
95
+ thread . setDaemon ( @daemonize )
96
+ return thread
97
+ end
98
+ end
99
+
84
100
end
85
101
end
Original file line number Diff line number Diff line change @@ -19,7 +19,9 @@ def initialize(opts = {})
19
19
private
20
20
21
21
def ns_initialize ( opts )
22
- @executor = java . util . concurrent . Executors . newSingleThreadExecutor
22
+ @executor = java . util . concurrent . Executors . newSingleThreadExecutor (
23
+ DaemonThreadFactory . new ( ns_auto_terminate? )
24
+ )
23
25
@fallback_policy = opts . fetch ( :fallback_policy , :discard )
24
26
raise ArgumentError . new ( "#{ @fallback_policy } is not a valid fallback policy" ) unless FALLBACK_POLICY_CLASSES . keys . include? ( @fallback_policy )
25
27
end
Original file line number Diff line number Diff line change @@ -108,6 +108,8 @@ def ns_initialize(opts)
108
108
queue = java . util . concurrent . LinkedBlockingQueue . new ( @max_queue )
109
109
end
110
110
111
+ self . auto_terminate = opts . fetch ( :auto_terminate , true )
112
+
111
113
@executor = java . util . concurrent . ThreadPoolExecutor . new (
112
114
min_length ,
113
115
max_length ,
@@ -120,21 +122,5 @@ def ns_initialize(opts)
120
122
end
121
123
end
122
124
123
- class DaemonThreadFactory
124
- # hide include from YARD
125
- send :include , java . util . concurrent . ThreadFactory
126
-
127
- def initialize ( daemonize = true )
128
- @daemonize = daemonize
129
- end
130
-
131
- def newThread ( runnable )
132
- thread = java . util . concurrent . Executors . defaultThreadFactory ( ) . newThread ( runnable )
133
- thread . setDaemon ( @daemonize )
134
- return thread
135
- end
136
- end
137
-
138
- private_constant :DaemonThreadFactory
139
125
end
140
126
end
You can’t perform that action at this time.
0 commit comments