PHP code example of thesis / sync-once
1. Go to this page and download the library: Download thesis/sync-once library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
thesis / sync-once example snippets
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(),
);
}
public function publish(Message $message): void
{
$this
->publishChannel
->await(new TimeoutCancellation(10))
->publish($message);
}
}