Manual
Coordination and limits
Wait for a group, take a lock, limit a rate, share an event.
Introduction#
WaitGroup waits for a batch of coroutines that report their own completion, instead of a list of Fiber handles. RateLimiter lets events through at a fixed rate, shared by every coroutine that waits on it. Event is a plain listener list for code that fires something and moves on, without a coroutine to wait. LockInterface and Synchronized serialize access to one PHP resource that only one coroutine may use at a time.
Guides#
- WaitGroup – Wait for a group of coroutines.
- RateLimiter – Limit how often something happens.
Examples#
- All examples of this topic – 6 with their output.
Reference#
Event– A list of listeners that are called when the event is triggered.LockInterface– An object that runs a closure while holding a lock that other coroutines wait for.LockTrait– Implements LockInterface: a lock that is reentrant for the coroutine holding it and fair for the others.RateLimiter– Lets events pass at a fixed rate, shared by every coroutine that calls wait().Synchronized– A mutex for coroutines, identified by a string or an object: only one coroutine at a time runs a closure for the same token.WaitGroup– Waits until a counted amount of work has been done, like Go's sync.WaitGroup.