Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
72 lines
2.4 KiB
Markdown
72 lines
2.4 KiB
Markdown
# Implementation Notes
|
|
|
|
This document describes implementation details that explain observable behavior
|
|
in `guzzlehttp/promises`, especially queue-based callback execution, iterative
|
|
resolution, and why `Promise` also acts as the deferred value. Application code
|
|
usually only needs the [Promise Quick Start](promise-quick-start.md) and
|
|
[Promise API](promise-api.md).
|
|
|
|
## Iterative Resolution and Chaining
|
|
|
|
Promises are resolved iteratively by moving pending handlers between promises.
|
|
This keeps stack size constant even for very long `then()` chains.
|
|
|
|
```php
|
|
<?php
|
|
require 'vendor/autoload.php';
|
|
|
|
use GuzzleHttp\Promise\Promise;
|
|
|
|
$parent = new Promise();
|
|
$p = $parent;
|
|
|
|
for ($i = 0; $i < 1000; $i++) {
|
|
$p = $p->then(function ($v) {
|
|
// The stack size remains constant.
|
|
echo xdebug_get_stack_depth() . ', ';
|
|
return $v + 1;
|
|
});
|
|
}
|
|
|
|
$parent->resolve(0);
|
|
var_dump($p->wait()); // int(1000)
|
|
|
|
```
|
|
|
|
When a promise is fulfilled or rejected with a non-promise value, the promise
|
|
takes ownership of each child promise's handlers and delivers values down the
|
|
chain without recursion.
|
|
|
|
When a promise is resolved with another promise, the original promise transfers
|
|
all of its pending handlers to the new promise. When the new promise is
|
|
eventually resolved, all pending handlers receive the forwarded
|
|
value.
|
|
|
|
## A Promise Is the Deferred
|
|
|
|
Some promise libraries implement promises using a deferred object to represent
|
|
a computation and a promise object to represent the delivery of the result of
|
|
the computation. That separation prevents consumers from modifying the value
|
|
that will eventually be delivered.
|
|
|
|
Iterative resolution requires one promise to move handlers from another promise.
|
|
To do that without making handlers publicly mutable, `Promise` is also the
|
|
deferred value. Promises of the same class can modify each other's private
|
|
state, including handler ownership. This means a consumer that receives a
|
|
`Promise` can also resolve or reject it, but it keeps chaining efficient and
|
|
stack safe.
|
|
|
|
```php
|
|
$promise = new Promise();
|
|
$promise->then(function ($value) { echo $value; });
|
|
// The promise is the deferred value, so you can deliver a value to it.
|
|
$promise->resolve('foo');
|
|
GuzzleHttp\Promise\Utils::queue()->run();
|
|
// Prints "foo"
|
|
```
|
|
|
|
## Related
|
|
|
|
- [Quick Start](promise-quick-start.md)
|
|
- [Promise API](promise-api.md)
|
|
- [Promise Interoperability](promise-interoperability.md)
|