Skip to content

Commit b57b483

Browse files
authored
Merge pull request #866 from pelly/master
Child promise state not set to :pending immediately after #execute when parent has completed
2 parents 663fe73 + a14fdc6 commit b57b483

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/concurrent-ruby/concurrent/promise.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def execute
250250
realize(@promise_body)
251251
end
252252
else
253+
compare_and_set_state(:pending, :unscheduled)
253254
@parent.execute
254255
end
255256
self

spec/concurrent/promise_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ def get_ivar_from_args(opts)
195195
end_latch.count_down
196196
end
197197
end
198+
199+
context "when called on child after parent completes" do
200+
let(:parent_promise) { Concurrent::Promise.execute { 1 + 1 }.tap { |p| p.wait } }
201+
it 'sets state to :pending immediately' do
202+
child_promise = parent_promise.then { |two| two + 2 }.execute
203+
expect(child_promise.state).to eq(:pending)
204+
end
205+
end
198206
end
199207
end
200208

0 commit comments

Comments
 (0)