Skip to content

Commit a14fdc6

Browse files
committed
bug fix (& spec): After parent has completed (via #wait, #value, etc), creating a child promise (via #then, #on_success, etc) and calling child_promise.execute.state return :unscheduled. It should return :pending
1 parent 7dc6eb0 commit a14fdc6

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)