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.
DataFetcher service layer).Laravel\Promises) or external event loops.dispatch() calls or Bus::dispatch() for chained execution (e.g., Promise::all([job1(), job2()])).GuzzlePromise::send()).event1.then(() => event2)).Promise::resolve(DB::select(...))).catch blocks must use callbacks, risking inconsistent error surfaces if not disciplined (e.g., unhandled rejections).Promise::all() calls)..then() chaining, combinators).Illuminate\Support\Facades\Bus or Illuminate\Queue suffice, or is a Promise layer necessary for composability?Promise::all([fetchUser(), fetchOrders()])).Promise::then() after dispatch()).event1.then(() => processEvent2())).Promise::resolve(DB::transaction(...))).Promise facade for global access (e.g., app('promise')).Bus or Queue to return Promises natively (e.g., Bus::dispatchAsPromise($job)).Mockery or Laravel\Promises test helpers to stub Promise resolutions.Pilot Phase (1–2 Weeks):
Promise::all() → aggregate data)..catch() blocks).// Before (Callbacks)
$client->request('GET', '/user')->then(function ($user) {
$client->request('GET', '/orders')->then(function ($orders) {
return $user + $orders;
});
});
// After (Promises)
Promise::all([
$client->request('GET', '/user'),
$client->request('GET', '/orders')
])->then(function ($results) {
return array_merge($results[0], $results[1]);
});
Core Integration (2–4 Weeks):
Promise::dispatch($job) to wrap Bus::dispatch()).Promise::race(), Promise::any(), Promise::allSettled()).// Queue Worker with Promises
class ProcessOrder implements ShouldQueue {
public function handle() {
return Promise::all([
$this->fetchUserData(),
$this->validatePayment(),
])->then(function ($results) {
// Process results
})->catch(function ($e) {
Log::error("Order processing failed: " . $e->getMessage());
});
}
}
Tooling and Observability (4+ Weeks):
dispatch() calls but do not replace the queue system. Useful for orchestrating dependent jobs.GuzzlePromise::send($request)).Event::dispatch() with Promises for async listeners.illuminate/promises, evaluate whether this library adds value (e.g., for cross-framework compatibility).| Phase | Duration | Focus Areas | Deliverables |
|---|---|---|---|
| Pilot | 1–2 weeks | Replace callbacks in a single |
How can I help you explore Laravel packages today?