Skip to content

Commit 60deb03

Browse files
committed
OptionsParser::get_executor_from is now a module function.
1 parent 6d0db54 commit 60deb03

File tree

6 files changed

+15
-22
lines changed

6 files changed

+15
-22
lines changed

lib/concurrent/agent.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ module Concurrent
3535
class Agent
3636
include Dereferenceable
3737
include Concurrent::Observable
38-
include OptionsParser
3938

4039
# The default timeout value (in seconds); used when no timeout option
4140
# is given at initialization
@@ -66,7 +65,7 @@ def initialize(initial, opts = {})
6665
@validator = Proc.new { |result| true }
6766
@timeout = opts.fetch(:timeout, TIMEOUT).freeze
6867
self.observers = CopyOnWriteObserverSet.new
69-
@executor = get_executor_from(opts)
68+
@executor = OptionsParser::get_executor_from(opts)
7069
init_mutex
7170
set_deref_options(opts)
7271
end

lib/concurrent/executor/timer_set.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ module Concurrent
1212
# time. Tasks are run on the global task pool or on the supplied executor.
1313
class TimerSet
1414
include Executor
15-
include OptionsParser
1615

1716
# Create a new set of timed tasks.
1817
#
@@ -24,7 +23,7 @@ class TimerSet
2423
# this executor rather than the global thread pool (overrides :operation)
2524
def initialize(opts = {})
2625
@queue = PriorityQueue.new(order: :min)
27-
@task_executor = get_executor_from(opts)
26+
@task_executor = OptionsParser::get_executor_from(opts)
2827
@timer_executor = SingleThreadExecutor.new
2928
@condition = Condition.new
3029
init_executor

lib/concurrent/future.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ module Concurrent
4141
# @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Future.html java.util.concurrent.Future
4242
class Future < IVar
4343
include Obligation
44-
include OptionsParser
4544

4645
# Create a new `Future` in the `:unscheduled` state.
4746
#
@@ -64,7 +63,7 @@ def initialize(opts = {}, &block)
6463
super(IVar::NO_VALUE, opts)
6564
@state = :unscheduled
6665
@task = block
67-
@executor = get_executor_from(opts)
66+
@executor = OptionsParser::get_executor_from(opts)
6867
end
6968

7069
# Execute an `:unscheduled` `Future`. Immediately sets the state to `:pending` and

lib/concurrent/options_parser.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ def get_executor_from(opts = {})
2020
Concurrent.configuration.global_task_pool
2121
end
2222
end
23+
module_function :get_executor_from
2324
end
2425
end

lib/concurrent/promise.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module Concurrent
77

88
class Promise
99
include Obligation
10-
include OptionsParser
1110

1211
# Initialize a new Promise with the provided options.
1312
#
@@ -33,7 +32,7 @@ class Promise
3332
def initialize(opts = {}, &block)
3433
opts.delete_if {|k, v| v.nil?}
3534

36-
@executor = get_executor_from(opts)
35+
@executor = OptionsParser::get_executor_from(opts)
3736
@parent = opts.fetch(:parent) { nil }
3837
@on_fulfill = opts.fetch(:on_fulfill) { Proc.new{ |result| result } }
3938
@on_reject = opts.fetch(:on_reject) { Proc.new{ |reason| raise reason } }

spec/concurrent/options_parser_spec.rb

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ module Concurrent
44

55
describe OptionsParser do
66

7-
subject do
8-
Class.new{ include OptionsParser }.new
9-
end
10-
117
let(:executor){ ImmediateExecutor.new }
128

139
let(:task_pool){ ImmediateExecutor.new }
@@ -16,59 +12,59 @@ module Concurrent
1612
context '#get_executor_from' do
1713

1814
it 'returns the given :executor' do
19-
subject.get_executor_from(executor: executor).should eq executor
15+
OptionsParser::get_executor_from(executor: executor).should eq executor
2016
end
2117

2218
it 'returns the global operation pool when :operation is true' do
2319
Concurrent.configuration.should_receive(:global_operation_pool).
2420
and_return(:operation_pool)
25-
subject.get_executor_from(operation: true)
21+
OptionsParser::get_executor_from(operation: true)
2622
end
2723

2824
it 'returns the global task pool when :operation is false' do
2925
Concurrent.configuration.should_receive(:global_task_pool).
3026
and_return(:task_pool)
31-
subject.get_executor_from(operation: false)
27+
OptionsParser::get_executor_from(operation: false)
3228
end
3329

3430
it 'returns the global operation pool when :task is false' do
3531
Concurrent.configuration.should_receive(:global_operation_pool).
3632
and_return(:operation_pool)
37-
subject.get_executor_from(task: false)
33+
OptionsParser::get_executor_from(task: false)
3834
end
3935

4036
it 'returns the global task pool when :task is true' do
4137
Concurrent.configuration.should_receive(:global_task_pool).
4238
and_return(:task_pool)
43-
subject.get_executor_from(task: true)
39+
OptionsParser::get_executor_from(task: true)
4440
end
4541

4642
it 'returns the global task pool when :executor is nil' do
4743
Concurrent.configuration.should_receive(:global_task_pool).
4844
and_return(:task_pool)
49-
subject.get_executor_from(executor: nil)
45+
OptionsParser::get_executor_from(executor: nil)
5046
end
5147

5248
it 'returns the global task pool when no option is given' do
5349
Concurrent.configuration.should_receive(:global_task_pool).
5450
and_return(:task_pool)
55-
subject.get_executor_from
51+
OptionsParser::get_executor_from
5652
end
5753

5854
specify ':executor overrides :operation' do
59-
subject.get_executor_from(executor: executor, operation: true).
55+
OptionsParser::get_executor_from(executor: executor, operation: true).
6056
should eq executor
6157
end
6258

6359
specify ':executor overrides :task' do
64-
subject.get_executor_from(executor: executor, task: true).
60+
OptionsParser::get_executor_from(executor: executor, task: true).
6561
should eq executor
6662
end
6763

6864
specify ':operation overrides :task' do
6965
Concurrent.configuration.should_receive(:global_operation_pool).
7066
and_return(:operation_pool)
71-
subject.get_executor_from(operation: true, task: true)
67+
OptionsParser::get_executor_from(operation: true, task: true)
7268
end
7369
end
7470
end

0 commit comments

Comments
 (0)