switon / sync
In-process channels, mutexes, wait groups, and stacks for coroutine-aware coordination for Switon Framework
v1.0.0
2026-06-06 13:43 UTC
Requires
- php: >=8.3
- switon/core: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- switon/testing: ^1.0
README
Switon's synchronization primitives for bounded handoff, mutual exclusion, task joining, and LIFO reuse in coroutine and non-coroutine runtimes.
Highlights
- Coroutine-friendly primitives: the same contracts work in coroutine and non-coroutine runtimes.
- Bounded channels:
Channelprovides fixed-capacity FIFO handoff. - Scoped mutexes:
Mutex::guard()returns a lock for deterministic release. - Task joining:
WaitGroupblocks until registered work finishes. - LIFO reuse:
Stackprovides fixed-capacity last-in-first-out reuse.
Installation
composer require switon/sync
Quick Start
use Switon\Sync\Channel; use Switon\Sync\Mutex; use Switon\Sync\WaitGroup; $channel = new Channel(2); $channel->push('task-1'); $task = $channel->pop(); $mutex = new Mutex(); $lock = $mutex->guard(); try { // critical section } finally { $lock->release(); } $wg = WaitGroup::of(2); $wg->done(); $wg->done(); $wg->wait();
Docs: https://docs.switon.dev/latest/sync
License
MIT.