-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[12.x] Fix PendingRequest@pool() && batch() concurrency
#57973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cosmastech
wants to merge
22
commits into
laravel:12.x
Choose a base branch
from
cosmastech:patch-35
base: 12.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+158
−23
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
abadd52
indicate what concurrency does
cosmastech e1101b1
Update PendingRequest.php
cosmastech 7679976
Change default concurrency to 0 in pool method
taylorotwell 28b52e6
Update PendingRequest.php
cosmastech ba374c0
Update FluentPromise.php
cosmastech 7305fa5
types and pending
cosmastech 8b824d4
laziness and the benefits therein
cosmastech 12fdfeb
wip
cosmastech a8105c8
FluentPromise is dead, long live LazyPromise
cosmastech 5911d2d
clean up
cosmastech 5caea0f
fix test
cosmastech 2355a99
actually, FluentPromise still has its place
cosmastech a84c5e5
clean up LazyPromise
cosmastech 8e8427c
backwards compatibility
cosmastech bea0372
remove unused trait
cosmastech 4a74bc1
return concurrency to null
cosmastech 79fdf65
fix Batch
cosmastech e1811c3
static analysis
cosmastech 823a70c
convert to generator
cosmastech fbc8d12
clean up PendingRequest
cosmastech 7f6e4b8
clean up Batch
cosmastech cc5a13a
static all the things
cosmastech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
2 changes: 1 addition & 1 deletion
2
src/Illuminate/Http/Client/FluentPromise.php → ...te/Http/Client/Promises/FluentPromise.php
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| <?php | ||
|
|
||
| namespace Illuminate\Http\Client\Promises; | ||
|
|
||
| use Closure; | ||
| use GuzzleHttp\Promise\PromiseInterface; | ||
| use RuntimeException; | ||
|
|
||
| class LazyPromise implements PromiseInterface | ||
| { | ||
| /** | ||
| * The callbacks to execute after the Guzzle Promise has been built. | ||
| * | ||
| * @var list<callable> | ||
| */ | ||
| protected array $pending = []; | ||
|
|
||
| /** | ||
| * The promise built by the creator. | ||
| * | ||
| * @var \GuzzleHttp\Promise\PromiseInterface | ||
| */ | ||
| protected PromiseInterface $guzzlePromise; | ||
|
|
||
| /** | ||
| * Create a new lazy promise instance. | ||
| * | ||
| * @param (\Closure(): \GuzzleHttp\Promise\PromiseInterface) $promiseBuilder The callback to build a new PromiseInterface. | ||
| */ | ||
| public function __construct(protected Closure $promiseBuilder) | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Build the promise from the promise builder. | ||
| * | ||
| * @return \GuzzleHttp\Promise\PromiseInterface | ||
| * | ||
| * @throws \RuntimeException If the promise has already been built | ||
| */ | ||
| public function buildPromise(): PromiseInterface | ||
| { | ||
| if (! $this->promiseNeedsBuilt()) { | ||
| throw new RuntimeException('Promise already built'); | ||
| } | ||
|
|
||
| $this->guzzlePromise = call_user_func($this->promiseBuilder); | ||
|
|
||
| foreach ($this->pending as $pendingCallback) { | ||
| $pendingCallback($this->guzzlePromise); | ||
| } | ||
|
|
||
| return $this->guzzlePromise; | ||
| } | ||
|
|
||
| /** | ||
| * If the promise has been created from the promise builder. | ||
| * | ||
| * @return bool | ||
| */ | ||
| public function promiseNeedsBuilt(): bool | ||
| { | ||
| return ! isset($this->guzzlePromise); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function then(?callable $onFulfilled = null, ?callable $onRejected = null): PromiseInterface | ||
| { | ||
| $this->pending[] = static fn (PromiseInterface $promise) => $promise->then($onFulfilled, $onRejected); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function otherwise(callable $onRejected): PromiseInterface | ||
| { | ||
| $this->pending[] = static fn (PromiseInterface $promise) => $promise->otherwise($onRejected); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getState(): string | ||
| { | ||
| if ($this->promiseNeedsBuilt()) { | ||
| return PromiseInterface::PENDING; | ||
| } | ||
|
|
||
| return $this->guzzlePromise->getState(); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function resolve($value): void | ||
| { | ||
| throw new \LogicException('Cannot resolve a lazy promise.'); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function reject($reason): void | ||
| { | ||
| throw new \LogicException('Cannot reject a lazy promise.'); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function cancel(): void | ||
| { | ||
| throw new \LogicException('Cannot cancel a lazy promise.'); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function wait(bool $unwrap = true) | ||
| { | ||
| if ($this->promiseNeedsBuilt()) { | ||
| $this->buildPromise(); | ||
| } | ||
|
|
||
| return $this->guzzlePromise->wait($unwrap); | ||
| } | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could possibly merge the behavior of FluentPromise with this by doing something like: