azjezz/psl
PSL (PHP Standard Library) offers a consistent, well-typed set of safer, async-ready APIs to replace PHP primitives. Covers async, collections, networking, I/O, cryptography, terminal UI, and type-safe data validation with predictable errors.
The Promise component provides a promise interface for deferred computations. A promise represents a value that will be available in the future -- either resolved with a success value or rejected with an exception. You attach callbacks to react to the outcome without blocking.
PromiseInterface<T> defines four methods for composing asynchronous operations:
then() -- Handle both success and failure in one callmap() -- Transform the resolved valuecatch() -- Recover from rejectionalways() -- Run cleanup logic regardless of outcomeEvery method returns a new PromiseInterface, so you can chain them into pipelines.
map() applies a function to the resolved value. If the promise is rejected, the callback is skipped and the rejection propagates:
@example('async/promise-map.php')
catch() attaches a callback that is only invoked when the promise is rejected. The returned value becomes the new resolved value:
@example('async/promise-catch.php')
then() is a shortcut for chaining map() and catch():
@example('async/promise-then.php')
This is equivalent to:
@example('async/promise-then-equivalent.php')
always() runs a callback when the promise settles, regardless of whether it resolved or was rejected. The promise's value passes through unchanged (unless the callback throws):
@example('async/promise-always.php')
Because every method returns a new promise, you can compose multi-step async workflows:
@example('async/promise-pipeline.php')
always() to guarantee cleanup runsSee src/Psl/Promise/ for the full API.
How can I help you explore Laravel packages today?