switon/sync

In-process channels, mutexes, wait groups, and stacks for coroutine-aware coordination for Switon Framework

Maintainers

Package info

github.com/switon-php/sync

Documentation

pkg:composer/switon/sync

Statistics

Installs: 41

Dependents: 3

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-06 13:43 UTC

This package is auto-updated.

Last update: 2026-06-07 02:11:32 UTC


README

CI PHP 8.3+

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: Channel provides fixed-capacity FIFO handoff.
  • Scoped mutexes: Mutex::guard() returns a lock for deterministic release.
  • Task joining: WaitGroup blocks until registered work finishes.
  • LIFO reuse: Stack provides 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.