Adopt the state of promises used as resolutions per Promises/A+ - #241
Draft
GrahamCampbell wants to merge 1 commit into
Draft
Adopt the state of promises used as resolutions per Promises/A+#241GrahamCampbell wants to merge 1 commit into
GrahamCampbell wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolving a promise with another promise, or returning one from a
then()handler, settled the promise immediately:getState()reportedfulfilledwhile the inner promise was still pending, andwait()could later throw on a promise whose state said it had fulfilled, violating Promises/A+ section 2.3.2. The promise now stays pending and adopts the thenable's eventual state, adopting an already-settled promise synchronously so that state polling around the synchronouswait()path keeps working. Handlers attached before adoption are merged onto the adopted promise behind a marker entry, which keeps dispatch as flat as the previous handler merge; a 5000-deep resolution chain runs within about 1.6 times the 3.x time while using a quarter of the memory. Rejection reasons are never adopted:reject()andCreate::rejectionFor()now refuse promises with anInvalidArgumentException, matchingRejectedPromise, and resolving or rejecting a promise with itself rejects it with aTypeErrorper section 2.3.1. Resolutions arriving while a promise adopts another promise are ignored per section 2.3.3.3.3, and cancelling an adopting promise forwards the cancellation to the adopted promise. Guzzle's full test suite passes unchanged against this branch. Drafted against 3.0 until a 4.0 branch is cut. Fixes #101.