Skip to content

Commit d794b95

Browse files
committed
Load WrappingExecutor only on newer Ruby
1 parent 03b75fd commit d794b95

File tree

3 files changed

+50
-49
lines changed

3 files changed

+50
-49
lines changed

lib-edge/concurrent-edge.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
require 'concurrent/agent'
77
require 'concurrent/channel'
88
require 'concurrent/lazy_register'
9-
require 'concurrent/executor/wrapping_executor'
9+
require 'concurrent/executor/wrapping_executor' if Concurrent.ruby_version :>=, 2, 1, 0
1010

1111
require 'concurrent/edge/lock_free_linked_set'
1212
require 'concurrent/edge/lock_free_queue'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module Concurrent
2+
RSpec.describe WrappingExecutor do
3+
4+
let(:wrapping_executor) { WrappingExecutor.new(executor, &wrapper) }
5+
let(:executor) { Concurrent.global_fast_executor }
6+
let(:wrapper) { nil }
7+
let(:args) { { foo: 'bar', baz: 42 } }
8+
let(:task) { -> (*args) { return nil } }
9+
10+
subject { wrapping_executor }
11+
12+
it { is_expected.to be_kind_of(WrappingExecutor) }
13+
it { is_expected.to respond_to(:post) }
14+
it { is_expected.to respond_to(:can_overflow?) }
15+
it { is_expected.to respond_to(:serialized?) }
16+
17+
describe '#post' do
18+
context 'with passthrough wrapper' do
19+
let(:wrapper) { -> (*args, &task) { return *args, task } }
20+
21+
it {
22+
expect(executor).to receive(:post).with(args) { |&block| expect(block).to be(task) }
23+
wrapping_executor.post(args, &task)
24+
}
25+
end
26+
27+
context 'with wrapper modifying args' do
28+
let(:wrapper) { -> (*args, &task) { return *args, { xyz: 'abc' }, task } }
29+
30+
it {
31+
expect(executor).to receive(:post).with(args, { xyz: 'abc' }) { |&block| expect(block).to be(task) }
32+
wrapping_executor.post(args, &task)
33+
}
34+
end
35+
36+
context 'with wrapper modifying task' do
37+
let(:wrapper) { -> (*args, &task) { return *args, another_task } }
38+
let(:another_task) { -> (*args) { return true } }
39+
40+
it {
41+
expect(executor).to receive(:post).with(args) { |&block| expect(block).to be(another_task) }
42+
wrapping_executor.post(args, &task)
43+
}
44+
end
45+
46+
end
47+
end
48+
end
Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1 @@
1-
module Concurrent
2-
RSpec.describe WrappingExecutor do
3-
4-
let(:wrapping_executor) { WrappingExecutor.new(executor, &wrapper) }
5-
let(:executor) { Concurrent.global_fast_executor }
6-
let(:wrapper) { nil }
7-
let(:args) { { foo: 'bar', baz: 42 } }
8-
let(:task) { -> (*args) { return nil } }
9-
10-
subject { wrapping_executor }
11-
12-
it { is_expected.to be_kind_of(WrappingExecutor) }
13-
it { is_expected.to respond_to(:post) }
14-
it { is_expected.to respond_to(:can_overflow?) }
15-
it { is_expected.to respond_to(:serialized?) }
16-
17-
describe '#post' do
18-
context 'with passthrough wrapper' do
19-
let(:wrapper) { -> (*args, &task) { return *args, task } }
20-
21-
it {
22-
expect(executor).to receive(:post).with(args) { |&block| expect(block).to be(task) }
23-
wrapping_executor.post(args, &task)
24-
}
25-
end
26-
27-
context 'with wrapper modifying args' do
28-
let(:wrapper) { -> (*args, &task) { return *args, { xyz: 'abc' }, task } }
29-
30-
it {
31-
expect(executor).to receive(:post).with(args, { xyz: 'abc' }) { |&block| expect(block).to be(task) }
32-
wrapping_executor.post(args, &task)
33-
}
34-
end
35-
36-
context 'with wrapper modifying task' do
37-
let(:wrapper) { -> (*args, &task) { return *args, another_task } }
38-
let(:another_task) { -> (*args) { return true } }
39-
40-
it {
41-
expect(executor).to receive(:post).with(args) { |&block| expect(block).to be(another_task) }
42-
wrapping_executor.post(args, &task)
43-
}
44-
end
45-
46-
end
47-
end
48-
end
1+
require_relative 'wrapping_executor_loaded_manualy' if Concurrent.ruby_version :>=, 2, 1, 0

0 commit comments

Comments
 (0)