thesis / sync-once
Thesis Sync Once
Fund package maintenance!
www.tinkoff.ru/cf/5MqZQas2dk7
Installs: 1 084
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.3
- amphp/amp: ^3.1
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8.2
- phpunit/phpunit: ^12.1.4
- symfony/var-dumper: ^6.4.15 || ^7.2.6
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); } }