thesis / sync-once
Thesis Sync Once
Fund package maintenance!
0.2.0
2026-07-09 01:40 UTC
Requires
- php: ^8.4
- amphp/amp: ^3.1
Requires (Dev)
- symfony/var-dumper: ^7.2.6
- testo/assert: ^0.1.11
- testo/codecov: ^0.1.11
- testo/test: ^0.1.6
- testo/testo: ^0.10.29
README
Installation
composer require thesis/sync-once
Usage
use Amp\TimeoutCancellation; use Thesis\Amqp\Channel; use Thesis\Amqp\Client; use Thesis\Amqp\Message; use Thesis\Sync\Once; final readonly class AmqpTransport { /** * @var Once<Channel> */ private Once $publishChannel; public function __construct( private Client $client, ) { $this->publishChannel = new Once( // make sure to use static closures to avoid circular references function: static fn (): Channel => $client->channel(), isAlive: static fn (Channel $channel): bool => !$channel->isClosed(), ); } public function publish(Message $message): void { $this ->publishChannel ->await(new TimeoutCancellation(10)) ->publish($message); } }