[12.x] Allow passing a callback to Pool@as()
#57963
Closed
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.
Guzzle Promises are immutable, which means userland chaining isn't possible since we don't have access to the underlying array.
For example, this will not work to return the string length of each request. It will instead just return the responses.
Were this PR to be accepted, then the above can be converted to:
Alternative
I do not feel like this is necessarily the most ergonomic solution as it's kinda callback hell, but it's a pretty big retooling to make this work otherwise.
We could allow forwarding calls to the PendingRequest to the underlying promise if the request is async. 🤷 I tried making this work with a
__callmethod on PendingRequest, but that still has the same problem where we are mutating state but it's not associated with the request. I think we would either need a Laravel-owned Promise that allows for fluent chaining (this isn't necessarily easy, since the Guzzle Promise has a lot of private state that we cannot access).Or maybe the PendingRequest is always based on Promises?