Skip to content

switon-php/sync

Repository files navigation

Switon Sync Package

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.

About

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

Topics

Resources

License

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages