Skip to content

Commit e5de92d

Browse files
AlexanderZagaynovpitr-ch
authored andcommitted
executor can have a name now
1 parent c85e099 commit e5de92d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/concurrent/executor/abstract_executor_service.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@ class AbstractExecutorService < Synchronization::LockableObject
1616
# @!macro executor_service_attr_reader_fallback_policy
1717
attr_reader :fallback_policy
1818

19+
attr_reader :name
20+
1921
# Create a new thread pool.
2022
def initialize(*args, &block)
2123
super(&nil)
22-
synchronize { ns_initialize(*args, &block) }
24+
synchronize do
25+
ns_initialize(*args, &block)
26+
opts = args.first || {}
27+
@name = opts.fetch(:name) if opts.key?(:name)
28+
end
29+
end
30+
31+
def to_s
32+
name ? "#{super[0..-2]} name: #{name}>" : super
2333
end
2434

2535
# @!macro executor_service_method_shutdown

spec/concurrent/executor/thread_pool_executor_shared.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
it 'defaults :fallback_policy to :abort' do
3232
expect(subject.fallback_policy).to eq :abort
3333
end
34+
35+
it 'defaults :name to nil' do
36+
expect(subject.name).to be_nil
37+
end
3438
end
3539

3640
context "#initialize explicit values" do
@@ -100,6 +104,13 @@
100104
described_class.new(fallback_policy: :bogus)
101105
}.to raise_error(ArgumentError)
102106
end
107+
108+
it 'sets :name' do
109+
pool = described_class.new(name: 'MyPool')
110+
expect(pool.name).to eq 'MyPool'
111+
pool.shutdown
112+
pool.wait_for_termination(pool_termination_timeout)
113+
end
103114
end
104115

105116
context '#max_queue' do

0 commit comments

Comments
 (0)