Skip to content

Commit

Permalink
bug fix (& spec): After parent has completed (via #wait, #value, etc)…
Browse files Browse the repository at this point in the history
…, creating a child promise (via #then, #on_success, etc) and calling child_promise.execute.state return :unscheduled. It should return :pending
  • Loading branch information
pelly committed Apr 24, 2020
1 parent 7dc6eb0 commit a14fdc6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/concurrent-ruby/concurrent/promise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def execute
realize(@promise_body)
end
else
compare_and_set_state(:pending, :unscheduled)
@parent.execute
end
self
Expand Down
8 changes: 8 additions & 0 deletions spec/concurrent/promise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ def get_ivar_from_args(opts)
end_latch.count_down
end
end

context "when called on child after parent completes" do
let(:parent_promise) { Concurrent::Promise.execute { 1 + 1 }.tap { |p| p.wait } }
it 'sets state to :pending immediately' do
child_promise = parent_promise.then { |two| two + 2 }.execute
expect(child_promise.state).to eq(:pending)
end
end
end
end

Expand Down

0 comments on commit a14fdc6

Please sign in to comment.