Skip to content

Commit 211697b

Browse files
committed
Future now protects mutation methods inherited from IVar.
1 parent 9fcc8a4 commit 211697b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/concurrent/future.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def self.execute(opts = {}, &block)
107107
return Future.new(opts, &block).execute
108108
end
109109

110+
protected :set, :fail, :complete
111+
110112
private
111113

112114
# @!visibility private

spec/concurrent/future_spec.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ def execute_dereferenceable(subject)
5858
it_should_behave_like :dereferenceable
5959
end
6060

61+
context 'subclassing' do
62+
63+
subject{ Future.execute{ 42 } }
64+
65+
it 'protects #set' do
66+
expect{ subject.set(100) }.to raise_error
67+
end
68+
69+
it 'protects #fail' do
70+
expect{ subject.fail }.to raise_error
71+
end
72+
73+
it 'protects #complete' do
74+
expect{ subject.complete(true, 100, nil) }.to raise_error
75+
end
76+
end
77+
6178
context '#initialize' do
6279

6380
it 'sets the state to :unscheduled' do
@@ -286,7 +303,6 @@ def reentrant_observer(future)
286303
obs.value.should eq 42
287304
end
288305
end
289-
290306
end
291307
end
292308
end

0 commit comments

Comments
 (0)