Skip to content

Commit

Permalink
Merge pull request #866 from pelly/master
Browse files Browse the repository at this point in the history
Child promise state not set to :pending immediately after #execute when parent has completed
  • Loading branch information
pitr-ch committed Jun 4, 2021
2 parents 663fe73 + a14fdc6 commit b57b483
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
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
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 b57b483

Please sign in to comment.