guzzlehttp/promises
Promises/A+ implementation for PHP with iterative, stack-safe chaining. Provides synchronous wait(), cancellation, interop with any thenable, and coroutine-style async/await via Coroutine::of(). Includes Promise, FulfilledPromise, and RejectedPromise.
Illuminate\Support\Facades\Http with async calls), though integration requires explicit wrapping.then() callbacks in Illuminate\Bus\Queueable jobs with promise chains for complex workflows.GuzzleHttp (Laravel’s default HTTP client) for async request handling, though Laravel’s Http::async() already uses promises under the hood.resolve() a promise in a service method).Promise::resolve() helper like response() or redirect()).wait().wait() for synchronous contexts or integrate with Laravel’s async tools (e.g., Http::async() + then()).then()/catch() chains can become hard to debug. Laravel’s exception handling (e.g., try/catch) may not seamlessly translate to promise rejections.otherwise() for rejection handling and wrap promises in Laravel’s try/catch where needed.guzzlehttp/promises v2 requires PHP ≥7.2.5. Ensure alignment with Laravel’s PHP version constraints.Http::async(), queues), or augment them? If the latter, how will they interoperate?GuzzleHttp\Promise\Coroutine replace Laravel’s Bus::dispatchSync() for async jobs?wait() be used, or will an event loop (e.g., ReactPHP) be introduced?Handler classes, middleware)? Will custom RejectionException handlers be needed?Mockery, Http::fake()) may need extensions for async assertions.Http::async() with GuzzleHttp\Promise for custom async logic (e.g., retry policies, parallel requests).JobA resolves to JobB).laravel-react) for event loop support.Promise::fromQueueJob()).class PromiseFacade {
public static function resolveFromJob(QueueableInterface $job) {
return new Promise(function () use ($job) {
$job->handle();
});
}
}
// In a ReactPHP event loop
$loop = React\EventLoop\Factory::create();
$loop->addPeriodicTimer(0.01, [GuzzleHttp\Promise\Utils::queue(), 'run']);
wait() for synchronous assertions or mock event loops for async tests.GuzzleHttp\Promise\Coroutine for async/await-style code.GuzzleHttp\Client instances can use GuzzleHttp\Promise via requestAsync():
$client = new Client();
$promise = $client->requestAsync('GET', 'https://api.example.com');
$promise->then(function (ResponseInterface $response) {
// Handle response
});
public function handle() {
$promise = new Promise(function () {
// Async operation (e.g., external API call)
});
$promise->then(function () {
dispatch(new FollowUpJob());
});
}
Illuminate\Http\Client\PendingRequest with then().guzzlehttp/promises for security updates (MIT license, active maintenance).getState() and custom logging to track promise lifecycles:
$promise->then(
fn($value) => logger()->debug('Fulfilled', ['value' => $value]),
fn($reason) => logger()->error('Rejected', ['reason' => $reason])
);
wait() for assertions.React\Promise\Timer for timeouts.How can I help you explore Laravel packages today?