Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Promise Laravel Package

php-standard-library/promise

Lightweight PHP promise implementation for composing and coordinating async-style workflows. Create, resolve, reject, and chain promises with then/catch-style handlers, useful for deferred results, task pipelines, and bridging callback-based APIs into a cleaner flow.

Deep Wiki
Context7

php-standard-library/promise provides a lightweight Promise implementation for PHP to model asynchronous workflows and deferred results. It helps you compose operations, handle success/failure consistently, and keep complex control flow readable without deeply nested callbacks.

Use it to build predictable async-like pipelines in libraries, CLI tools, or integrations where you need clean chaining, centralized error handling, and deterministic resolution.

  • Thenable chaining for sequential transformations and composition
  • Error propagation with dedicated rejection handling
  • Resolution control via deferred-style resolve/reject APIs
  • Interoperability with common promise patterns and callbacks
  • Readable flow for complex multi-step operations
Frequently asked questions about Promise
How do I install php-standard-library/promise in a Laravel project?
Run `composer require php-standard-library/promise` in your project root. The package has no Laravel-specific dependencies, so it integrates seamlessly with existing codebases. No service provider or facade setup is required unless you want to extend Laravel’s native features with Promise macros.
Can I use this package to chain HTTP requests (e.g., Guzzle) in Laravel?
Yes. Wrap Guzzle’s async requests in Promises using `new Promise(fn() => $client->request(...))` and chain them with `.then()` for sequential execution. For parallel requests, use `Promise::all()` to aggregate results. This avoids nested callbacks and keeps your HTTP logic clean and composable.
Does this package work with Laravel Queues or Horizon?
It integrates indirectly. You can wrap `dispatch()` calls in Promises to chain queue jobs (e.g., `Promise::all([dispatch('Job1'), dispatch('Job2')])`), but the package itself doesn’t replace Laravel’s queue system. For monitoring, you’d need custom Telescope channels or logging to track Promise resolutions alongside Horizon.
What PHP and Laravel versions does php-standard-library/promise support?
The package targets PHP 8.1+ and is compatible with Laravel 9/10. It avoids heavy dependencies, so it won’t conflict with Laravel’s core. Always check the package’s `composer.json` for the latest version constraints, as minor updates may align with newer Laravel releases.
How do I handle errors in a Promise chain in Laravel?
Use `.catch()` to handle rejections. For global error tracking, integrate with Laravel’s logging (e.g., `Log::error($reason)` in the catch block) or Sentry. Unhandled rejections will throw exceptions, so ensure critical Promises have catch handlers. Avoid silent failures by validating inputs before resolving.
Is this package suitable for production Laravel applications?
Yes, but with caveats. It’s lightweight and production-ready for bounded contexts like API clients or background jobs. Avoid using it for core business logic where synchronous flows are preferred. Test Promise-heavy paths thoroughly, especially error scenarios, and monitor performance in high-throughput environments.
Can I use Promises to replace Laravel’s Bus or Queue system entirely?
No. This package is for *composing* async operations, not replacing Laravel’s Bus or Queue. Use Promises to chain jobs or HTTP calls *within* a queue worker or command, but rely on Laravel’s Queues for actual async execution. For example, dispatch a job, then chain Promises to process its result.
How do I test Promise-based code in Laravel?
Mock Promises with Mockery by stubbing their `resolve()` or `reject()` methods. For example, `Mockery::mock('alias:Promise')->shouldReceive('then')->andReturnSelf()->once()`. Test both success and failure paths. Use Laravel’s `expectException()` to verify rejections. Avoid testing implementation details; focus on behavior.
Are there performance concerns with Promises in Laravel?
Minimal overhead for most use cases, but batch operations (e.g., `Promise::all()` with 100+ Promises) may impact memory. For high-load scenarios, consider parallelism limits or lazy resolution. Profile with Laravel Forge or Blackfire to identify bottlenecks, especially when mixing Promises with synchronous Laravel code.
What alternatives exist for async workflows in Laravel?
For simple async tasks, Laravel’s built-in `Bus` or `Queue` may suffice. For more complex composition, consider ReactPHP (event-loop based) or Amp (fiber-based), but they’re heavier. This package strikes a balance: lightweight, callback-free, and Laravel-friendly. Use it when you need chaining but don’t want a full async framework.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport