php-standard-library/promise
Lightweight Promise implementation for PHP with a simple, standards-inspired API. Create, resolve, reject, and chain async-style operations, handle errors, and compose results with familiar then/catch patterns—ideal for libraries that need non-blocking workflows.
Services layer) where async orchestration is required but a heavy framework (ReactPHP, Amp) is unnecessary.dispatch() calls or Bus jobs for chaining (e.g., Promise::all([job1(), job2()])).GuzzlePromise::send()).event1.then(() => event2)).Promise::then() with sync code).async/await means catch blocks still use callbacks, risking inconsistent error surfaces if misused.Mockery stubs for Promise::resolve()), increasing test complexity.Bus/Queue or PHP 8.1+ fibers suffice, or is a Promise layer necessary for composability?Promise::all([userApi(), ordersApi()])).Promise::then() for post-job processing).event1.then(() => event2)).Promise facade for global access (e.g., app('promise')).Bus or Queue to return Promises natively (e.g., Bus::promise($job)).Mockery to stub Promise resolutions in PHPUnit tests.Guzzle->then() to Promise::resolve(Guzzle->send())->then().Promise::dispatch($job)).Promise::race(), Promise::allSettled()).dispatch() but won’t replace the queue system (still need workers).GuzzlePromise::send()).Event::dispatch() with Promises for async listeners.Promise::allSettled())..then() chaining).finally for cleanup).Promise::all() with many slow operations) may need batching.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Unhandled Promise rejection | Silent crashes or partial failures | Global set_unhandled_rejection_handler() |
| Circular Promise dependencies | Memory leaks or deadlocks | Static analysis tools (e.g., Psalm) |
| Queue worker crashes | Broken async flows | Retry logic + Sentry alerts |
| Promise leak (unresolved) | Memory bloat | finally blocks or TTL for Promises |
| Mixed sync/async code | Race conditions | Clear architecture boundaries (e.g., "Promises only in X layer") |
.then() chains).Promise::resolve() stubs).How can I help you explore Laravel packages today?