- What is hyperf/coordinator used for?
- hyperf/coordinator provides coroutine coordination primitives for Hyperf applications. It lets coroutines pause at named wait points, resume when signalled, and coordinate worker lifecycle events such as graceful shutdown. It is useful for timers, background tasks, and other asynchronous workflows that should not busy wait.
- How do I install hyperf/coordinator?
- Install it with Composer by running composer require hyperf/coordinator in your Hyperf project. Then use the coordinator classes in the worker, timer, or lifecycle code where you need shared wait and resume behavior. Follow the package README for any version-specific registration or configuration details.
- Does hyperf/coordinator work with Laravel?
- No. hyperf/coordinator is a Hyperf component designed around Swoole coroutines, not a Laravel package, so Laravel version compatibility does not apply. For Laravel applications, use Laravel-native queues, events, and process management unless you are running Hyperf alongside Laravel.
- How do named coordinators work in hyperf/coordinator?
- Named coordinators give different parts of your application a shared wait/resume point identified by name. A coroutine can yield on that name and later be resumed by another part of the code, which avoids ad hoc polling loops. Use clear, unique names so worker and task coordination remains predictable.
- What do yield() and resume() do in hyperf/coordinator?
- yield() pauses the current coroutine at a coordinator wait point, while resume() signals that wait point so the coroutine can continue. They are coroutine-safe primitives intended to replace busy waiting with explicit coordination. Use them with named coordinators when one part of your code must wait for another event or worker state change.
- How does hyperf/coordinator help with graceful worker shutdown?
- CoordinatorManager provides application-wide lifecycle coordination and exit-event waiting. It helps workers wait for shutdown signals or exit events and then stop safely instead of spinning or terminating abruptly. This makes graceful shutdown easier to reason about in long-running Hyperf and Swoole services.
- Can hyperf/coordinator handle timed tasks and background workflows?
- Yes. The package is designed for asynchronous workflows such as timed tasks and background jobs where a coroutine needs to wait for a signal. You can coordinate timers, worker tasks, and shutdown paths with named wait/resume points. It is lightweight, so it fits small coordination needs without pulling in a larger workflow engine.
- Is hyperf/coordinator safe for Swoole coroutines and multiple workers?
- The API is built for Swoole coroutines in Hyperf and is intended to be coroutine-safe when used correctly. In production, use timeouts or guard conditions so a coroutine does not wait forever if the expected resume never arrives. Also ensure that resume calls come from the intended worker or lifecycle event, especially when multiple workers are involved.
- How do I test code that uses hyperf/coordinator?
- Test coordinator code inside a Hyperf/Swoole coroutine context when possible, and assert that a yielded coroutine resumes only after the matching resume call. For shutdown behavior, simulate exit events and verify your workers complete without busy waiting. Use named coordinators and explicit timeouts to keep tests deterministic.
- What are alternatives to hyperf/coordinator and is it maintained?
- Alternatives include Swoole coroutine channels, Hyperf's built-in coroutine utilities, or small custom wait/resume implementations. hyperf/coordinator is focused and lightweight, but you should check the Hyperf repository for current release activity and compatibility with your Hyperf version. For Laravel-first stacks, Laravel queues and events are usually the better fit.